Update Values in a dataframe by merging











up vote
0
down vote

favorite












I have got two dataframes; the first is an empty one, with dates as rows and Products as columns. The second contains the value of the inventory, for a specific item.



The rows and the columns that are in the latter appear in the first one as well:



print(inventory_df)

dt_op Prod_1 Prod_2 ... Prod_n
10/09/18 0 0 0
11/09/18 0 0 0
12/09/18 0 0 0

...

print(final_inspect)

dt_op Prod_1
10/09/18 10
11/09/18 2
12/09/18 5


I would like to update the values in inventory_df, obtaining the following dataframe:



print(updated_df)
dt_op Prod_1 Prod_2 ... Prod_n
10/09/18 10 0 0
11/09/18 2 0 0
12/09/18 5 0 0

...


I tried with a redoundant method, concatenating and then removing duplicates, but when I use pd.concat it raises:



TypeError: cannot concatenate object of type "<class 'list'>"; only pd.Series, pd.DataFrame, and pd.Panel (deprecated) objs are valid


How can I merge the first two frames to create the updated one?



N.B. The size of updated_df has to be the same as inventory_df, and nrows of final_inspect are less than nrows of inventory_df.










share|improve this question




























    up vote
    0
    down vote

    favorite












    I have got two dataframes; the first is an empty one, with dates as rows and Products as columns. The second contains the value of the inventory, for a specific item.



    The rows and the columns that are in the latter appear in the first one as well:



    print(inventory_df)

    dt_op Prod_1 Prod_2 ... Prod_n
    10/09/18 0 0 0
    11/09/18 0 0 0
    12/09/18 0 0 0

    ...

    print(final_inspect)

    dt_op Prod_1
    10/09/18 10
    11/09/18 2
    12/09/18 5


    I would like to update the values in inventory_df, obtaining the following dataframe:



    print(updated_df)
    dt_op Prod_1 Prod_2 ... Prod_n
    10/09/18 10 0 0
    11/09/18 2 0 0
    12/09/18 5 0 0

    ...


    I tried with a redoundant method, concatenating and then removing duplicates, but when I use pd.concat it raises:



    TypeError: cannot concatenate object of type "<class 'list'>"; only pd.Series, pd.DataFrame, and pd.Panel (deprecated) objs are valid


    How can I merge the first two frames to create the updated one?



    N.B. The size of updated_df has to be the same as inventory_df, and nrows of final_inspect are less than nrows of inventory_df.










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have got two dataframes; the first is an empty one, with dates as rows and Products as columns. The second contains the value of the inventory, for a specific item.



      The rows and the columns that are in the latter appear in the first one as well:



      print(inventory_df)

      dt_op Prod_1 Prod_2 ... Prod_n
      10/09/18 0 0 0
      11/09/18 0 0 0
      12/09/18 0 0 0

      ...

      print(final_inspect)

      dt_op Prod_1
      10/09/18 10
      11/09/18 2
      12/09/18 5


      I would like to update the values in inventory_df, obtaining the following dataframe:



      print(updated_df)
      dt_op Prod_1 Prod_2 ... Prod_n
      10/09/18 10 0 0
      11/09/18 2 0 0
      12/09/18 5 0 0

      ...


      I tried with a redoundant method, concatenating and then removing duplicates, but when I use pd.concat it raises:



      TypeError: cannot concatenate object of type "<class 'list'>"; only pd.Series, pd.DataFrame, and pd.Panel (deprecated) objs are valid


      How can I merge the first two frames to create the updated one?



      N.B. The size of updated_df has to be the same as inventory_df, and nrows of final_inspect are less than nrows of inventory_df.










      share|improve this question















      I have got two dataframes; the first is an empty one, with dates as rows and Products as columns. The second contains the value of the inventory, for a specific item.



      The rows and the columns that are in the latter appear in the first one as well:



      print(inventory_df)

      dt_op Prod_1 Prod_2 ... Prod_n
      10/09/18 0 0 0
      11/09/18 0 0 0
      12/09/18 0 0 0

      ...

      print(final_inspect)

      dt_op Prod_1
      10/09/18 10
      11/09/18 2
      12/09/18 5


      I would like to update the values in inventory_df, obtaining the following dataframe:



      print(updated_df)
      dt_op Prod_1 Prod_2 ... Prod_n
      10/09/18 10 0 0
      11/09/18 2 0 0
      12/09/18 5 0 0

      ...


      I tried with a redoundant method, concatenating and then removing duplicates, but when I use pd.concat it raises:



      TypeError: cannot concatenate object of type "<class 'list'>"; only pd.Series, pd.DataFrame, and pd.Panel (deprecated) objs are valid


      How can I merge the first two frames to create the updated one?



      N.B. The size of updated_df has to be the same as inventory_df, and nrows of final_inspect are less than nrows of inventory_df.







      python pandas merge






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 at 14:25

























      asked Nov 19 at 12:31









      Alessandro Ceccarelli

      216210




      216210
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          Use df.update()-



          inventory_df.update(final_inspect)


          Output



              dt_op   Prod_1  Prod_2
          0 10/09/18 10 0
          1 11/09/18 2 0
          2 12/09/18 5 0


          This by default implements a join='left, wherein you can take care of non-matching na values as you wish






          share|improve this answer





















          • It does not seem to produce a result; the function should be the right one but it does not update the dataframe. What could be the reasons?
            – Alessandro Ceccarelli
            Nov 19 at 14:22










          • @AlessandroCeccarelli It updates the df inplace, i.e. the inventory_df is updated directly
            – Vivek Kalyanarangan
            Nov 19 at 14:25










          • I know, but at the moment, whenever I run "inventory_df.update(final_inspect)", inventory_df is not changed, even though there are not missing values, and the columns are the same.
            – Alessandro Ceccarelli
            Nov 19 at 14:39












          • Thats funny, not sure what might be going wrong, working fine for me :(
            – Vivek Kalyanarangan
            Nov 19 at 14:43












          • It does not work on my dataframe, nonetheless it does work with some other examples I've made for testing purposes.
            – Alessandro Ceccarelli
            Nov 19 at 16:12













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374729%2fupdate-values-in-a-dataframe-by-merging%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote



          accepted










          Use df.update()-



          inventory_df.update(final_inspect)


          Output



              dt_op   Prod_1  Prod_2
          0 10/09/18 10 0
          1 11/09/18 2 0
          2 12/09/18 5 0


          This by default implements a join='left, wherein you can take care of non-matching na values as you wish






          share|improve this answer





















          • It does not seem to produce a result; the function should be the right one but it does not update the dataframe. What could be the reasons?
            – Alessandro Ceccarelli
            Nov 19 at 14:22










          • @AlessandroCeccarelli It updates the df inplace, i.e. the inventory_df is updated directly
            – Vivek Kalyanarangan
            Nov 19 at 14:25










          • I know, but at the moment, whenever I run "inventory_df.update(final_inspect)", inventory_df is not changed, even though there are not missing values, and the columns are the same.
            – Alessandro Ceccarelli
            Nov 19 at 14:39












          • Thats funny, not sure what might be going wrong, working fine for me :(
            – Vivek Kalyanarangan
            Nov 19 at 14:43












          • It does not work on my dataframe, nonetheless it does work with some other examples I've made for testing purposes.
            – Alessandro Ceccarelli
            Nov 19 at 16:12

















          up vote
          0
          down vote



          accepted










          Use df.update()-



          inventory_df.update(final_inspect)


          Output



              dt_op   Prod_1  Prod_2
          0 10/09/18 10 0
          1 11/09/18 2 0
          2 12/09/18 5 0


          This by default implements a join='left, wherein you can take care of non-matching na values as you wish






          share|improve this answer





















          • It does not seem to produce a result; the function should be the right one but it does not update the dataframe. What could be the reasons?
            – Alessandro Ceccarelli
            Nov 19 at 14:22










          • @AlessandroCeccarelli It updates the df inplace, i.e. the inventory_df is updated directly
            – Vivek Kalyanarangan
            Nov 19 at 14:25










          • I know, but at the moment, whenever I run "inventory_df.update(final_inspect)", inventory_df is not changed, even though there are not missing values, and the columns are the same.
            – Alessandro Ceccarelli
            Nov 19 at 14:39












          • Thats funny, not sure what might be going wrong, working fine for me :(
            – Vivek Kalyanarangan
            Nov 19 at 14:43












          • It does not work on my dataframe, nonetheless it does work with some other examples I've made for testing purposes.
            – Alessandro Ceccarelli
            Nov 19 at 16:12















          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          Use df.update()-



          inventory_df.update(final_inspect)


          Output



              dt_op   Prod_1  Prod_2
          0 10/09/18 10 0
          1 11/09/18 2 0
          2 12/09/18 5 0


          This by default implements a join='left, wherein you can take care of non-matching na values as you wish






          share|improve this answer












          Use df.update()-



          inventory_df.update(final_inspect)


          Output



              dt_op   Prod_1  Prod_2
          0 10/09/18 10 0
          1 11/09/18 2 0
          2 12/09/18 5 0


          This by default implements a join='left, wherein you can take care of non-matching na values as you wish







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 at 12:38









          Vivek Kalyanarangan

          4,3681726




          4,3681726












          • It does not seem to produce a result; the function should be the right one but it does not update the dataframe. What could be the reasons?
            – Alessandro Ceccarelli
            Nov 19 at 14:22










          • @AlessandroCeccarelli It updates the df inplace, i.e. the inventory_df is updated directly
            – Vivek Kalyanarangan
            Nov 19 at 14:25










          • I know, but at the moment, whenever I run "inventory_df.update(final_inspect)", inventory_df is not changed, even though there are not missing values, and the columns are the same.
            – Alessandro Ceccarelli
            Nov 19 at 14:39












          • Thats funny, not sure what might be going wrong, working fine for me :(
            – Vivek Kalyanarangan
            Nov 19 at 14:43












          • It does not work on my dataframe, nonetheless it does work with some other examples I've made for testing purposes.
            – Alessandro Ceccarelli
            Nov 19 at 16:12




















          • It does not seem to produce a result; the function should be the right one but it does not update the dataframe. What could be the reasons?
            – Alessandro Ceccarelli
            Nov 19 at 14:22










          • @AlessandroCeccarelli It updates the df inplace, i.e. the inventory_df is updated directly
            – Vivek Kalyanarangan
            Nov 19 at 14:25










          • I know, but at the moment, whenever I run "inventory_df.update(final_inspect)", inventory_df is not changed, even though there are not missing values, and the columns are the same.
            – Alessandro Ceccarelli
            Nov 19 at 14:39












          • Thats funny, not sure what might be going wrong, working fine for me :(
            – Vivek Kalyanarangan
            Nov 19 at 14:43












          • It does not work on my dataframe, nonetheless it does work with some other examples I've made for testing purposes.
            – Alessandro Ceccarelli
            Nov 19 at 16:12


















          It does not seem to produce a result; the function should be the right one but it does not update the dataframe. What could be the reasons?
          – Alessandro Ceccarelli
          Nov 19 at 14:22




          It does not seem to produce a result; the function should be the right one but it does not update the dataframe. What could be the reasons?
          – Alessandro Ceccarelli
          Nov 19 at 14:22












          @AlessandroCeccarelli It updates the df inplace, i.e. the inventory_df is updated directly
          – Vivek Kalyanarangan
          Nov 19 at 14:25




          @AlessandroCeccarelli It updates the df inplace, i.e. the inventory_df is updated directly
          – Vivek Kalyanarangan
          Nov 19 at 14:25












          I know, but at the moment, whenever I run "inventory_df.update(final_inspect)", inventory_df is not changed, even though there are not missing values, and the columns are the same.
          – Alessandro Ceccarelli
          Nov 19 at 14:39






          I know, but at the moment, whenever I run "inventory_df.update(final_inspect)", inventory_df is not changed, even though there are not missing values, and the columns are the same.
          – Alessandro Ceccarelli
          Nov 19 at 14:39














          Thats funny, not sure what might be going wrong, working fine for me :(
          – Vivek Kalyanarangan
          Nov 19 at 14:43






          Thats funny, not sure what might be going wrong, working fine for me :(
          – Vivek Kalyanarangan
          Nov 19 at 14:43














          It does not work on my dataframe, nonetheless it does work with some other examples I've made for testing purposes.
          – Alessandro Ceccarelli
          Nov 19 at 16:12






          It does not work on my dataframe, nonetheless it does work with some other examples I've made for testing purposes.
          – Alessandro Ceccarelli
          Nov 19 at 16:12




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374729%2fupdate-values-in-a-dataframe-by-merging%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Costa Masnaga

          Fotorealismo

          Sidney Franklin