calculate inventory turnover in python, taking difference using groupby?What is the difference between old style and new style classes in Python?What is the difference between Python's list methods append and extend?Use different Python version with virtualenvPeak detection in a 2D arrayUnicodeEncodeError: 'ascii' codec can't encode character u'xa0' in position 20: ordinal not in range(128)“Large data” work flows using pandasApply multiple functions to multiple groupby columnspandas create new column based on values from other columnsHow do I create a new column from the output of pandas groupby().sum()?replace certain number in DataFrame

Need help in optimizing the below helper class

What is realistic quality of computer blueprints quickly backed up before apocalypse and their impact on future design?

Is Norway in the Single Market?

A way of getting tenure for a non-creative person

What's the term for a group of people who enjoy literary works?

Plotting Chebyshev polynomials using PolarPlot and FilledCurve

How did Biff return to 2015 from 1955 without a lightning strike?

Went to a big 4 but got fired for underperformance in a year recently - Now every one thinks I'm pro - How to balance expectations?

Does KNN have a loss function?

Why is “deal 6 damage” a legit phrase?

Meaning of 誰かの代わりに

Is it really a problem to declare that a visitor to the UK is my "girlfriend", in terms of her successfully getting a Standard Visitor visa?

Move label of an angle in Tikz

Is this popular optical illusion made of a grey-scale image with coloured lines?

Selecting rows conflicting values in WHERE clause

What is the reason behind water not falling from a bucket at the top of loop?

The grades of the students in a class

Why are sugars in whole fruits not digested the same way sugars in juice are?

Reasons for using monsters as bioweapons

Is the EU really banning "toxic propellants" in 2020? How is that going to work?

How do people drown while wearing a life jacket?

How to get rid of leading zeros in a number?

Does the use of a new concept require a prior definition?

How does a wallet generate a public key from an address?



calculate inventory turnover in python, taking difference using groupby?


What is the difference between old style and new style classes in Python?What is the difference between Python's list methods append and extend?Use different Python version with virtualenvPeak detection in a 2D arrayUnicodeEncodeError: 'ascii' codec can't encode character u'xa0' in position 20: ordinal not in range(128)“Large data” work flows using pandasApply multiple functions to multiple groupby columnspandas create new column based on values from other columnsHow do I create a new column from the output of pandas groupby().sum()?replace certain number in DataFrame






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















i have a dataframe which contains inventory information. One column is product type (i.e A,B,C), one column is the number of inventory for each product, one column records the date (i.e day 1, day 2, day 3). For example (see the table below), on day 1, we have 1 product A; on day 2, we have 3 product A and 2 product B; on day 3, we have 6 product B.



product | inventory | day
A | 1 | 1
A | 3 | 2
B | 2 | 2
B | 6 | 3


I would like to calculate the product change for each day. The desired resulting table is shown below. The trick is that every day some products may be gone or some new product may come in. For example, on day 3, product A does not exist any more (in other words, all 3 product A on day 2 are gone on day 3). On day 2, new product B comes in as we do not have inventory for it on day 1. Remember, some product may disappear on certain day and come back later and then disappear again.



product | inventory_change | day
A | 1 | 1
A | 2 | 2
B | 2 | 2
A | -3 | 3
B | 4 | 3


I am sure i can use loop to go through each row to achieve it. I am wondering if there are any more efficient way to complete it without loop? I thinking use groupby, but still fail to come out a way without using loop, especially given available product list could be different every day (i.e day1:A, day2 A,B; day3: B) Any idea or suggestions?










share|improve this question






























    0















    i have a dataframe which contains inventory information. One column is product type (i.e A,B,C), one column is the number of inventory for each product, one column records the date (i.e day 1, day 2, day 3). For example (see the table below), on day 1, we have 1 product A; on day 2, we have 3 product A and 2 product B; on day 3, we have 6 product B.



    product | inventory | day
    A | 1 | 1
    A | 3 | 2
    B | 2 | 2
    B | 6 | 3


    I would like to calculate the product change for each day. The desired resulting table is shown below. The trick is that every day some products may be gone or some new product may come in. For example, on day 3, product A does not exist any more (in other words, all 3 product A on day 2 are gone on day 3). On day 2, new product B comes in as we do not have inventory for it on day 1. Remember, some product may disappear on certain day and come back later and then disappear again.



    product | inventory_change | day
    A | 1 | 1
    A | 2 | 2
    B | 2 | 2
    A | -3 | 3
    B | 4 | 3


    I am sure i can use loop to go through each row to achieve it. I am wondering if there are any more efficient way to complete it without loop? I thinking use groupby, but still fail to come out a way without using loop, especially given available product list could be different every day (i.e day1:A, day2 A,B; day3: B) Any idea or suggestions?










    share|improve this question


























      0












      0








      0








      i have a dataframe which contains inventory information. One column is product type (i.e A,B,C), one column is the number of inventory for each product, one column records the date (i.e day 1, day 2, day 3). For example (see the table below), on day 1, we have 1 product A; on day 2, we have 3 product A and 2 product B; on day 3, we have 6 product B.



      product | inventory | day
      A | 1 | 1
      A | 3 | 2
      B | 2 | 2
      B | 6 | 3


      I would like to calculate the product change for each day. The desired resulting table is shown below. The trick is that every day some products may be gone or some new product may come in. For example, on day 3, product A does not exist any more (in other words, all 3 product A on day 2 are gone on day 3). On day 2, new product B comes in as we do not have inventory for it on day 1. Remember, some product may disappear on certain day and come back later and then disappear again.



      product | inventory_change | day
      A | 1 | 1
      A | 2 | 2
      B | 2 | 2
      A | -3 | 3
      B | 4 | 3


      I am sure i can use loop to go through each row to achieve it. I am wondering if there are any more efficient way to complete it without loop? I thinking use groupby, but still fail to come out a way without using loop, especially given available product list could be different every day (i.e day1:A, day2 A,B; day3: B) Any idea or suggestions?










      share|improve this question














      i have a dataframe which contains inventory information. One column is product type (i.e A,B,C), one column is the number of inventory for each product, one column records the date (i.e day 1, day 2, day 3). For example (see the table below), on day 1, we have 1 product A; on day 2, we have 3 product A and 2 product B; on day 3, we have 6 product B.



      product | inventory | day
      A | 1 | 1
      A | 3 | 2
      B | 2 | 2
      B | 6 | 3


      I would like to calculate the product change for each day. The desired resulting table is shown below. The trick is that every day some products may be gone or some new product may come in. For example, on day 3, product A does not exist any more (in other words, all 3 product A on day 2 are gone on day 3). On day 2, new product B comes in as we do not have inventory for it on day 1. Remember, some product may disappear on certain day and come back later and then disappear again.



      product | inventory_change | day
      A | 1 | 1
      A | 2 | 2
      B | 2 | 2
      A | -3 | 3
      B | 4 | 3


      I am sure i can use loop to go through each row to achieve it. I am wondering if there are any more efficient way to complete it without loop? I thinking use groupby, but still fail to come out a way without using loop, especially given available product list could be different every day (i.e day1:A, day2 A,B; day3: B) Any idea or suggestions?







      python group-by






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 27 at 0:21









      AAAAAA

      1731 silver badge8 bronze badges




      1731 silver badge8 bronze badges

























          0






          active

          oldest

          votes










          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',
          autoActivateHeartbeat: false,
          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%2f55368034%2fcalculate-inventory-turnover-in-python-taking-difference-using-groupby%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes




          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55368034%2fcalculate-inventory-turnover-in-python-taking-difference-using-groupby%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

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해