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;
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
add a comment |
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
add a comment |
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
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
python group-by
asked Mar 27 at 0:21
AAAAAA
1731 silver badge8 bronze badges
1731 silver badge8 bronze badges
add a comment |
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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