Finding average on equal days using pandas
I have a data set, where I'm trying to get an average on days remaining that are equal.
Example:
ship_date Order_date cumulative_ordered days_remaining
2018-07-01 2018-05-06 7 56 days
2018-07-01 2018-05-07 10 55 days
2018-07-01 2018-05-08 15 54 days
The order_date will count down until it reaches the ship_date. by that time the cumulative order equals the total orders up until the shipping date. Then a new ship_date and the process repeats. I want to see the percentage average on each day up until the order date. For instance if ship_date 2018-07-01 has a total of 100 orders and ship_date 2018-08-01 has a total of 200, then I want to see how much percentage wise on average was ordered 54 days prior to ship_date.
Thanks.
python pandas average
add a comment |
I have a data set, where I'm trying to get an average on days remaining that are equal.
Example:
ship_date Order_date cumulative_ordered days_remaining
2018-07-01 2018-05-06 7 56 days
2018-07-01 2018-05-07 10 55 days
2018-07-01 2018-05-08 15 54 days
The order_date will count down until it reaches the ship_date. by that time the cumulative order equals the total orders up until the shipping date. Then a new ship_date and the process repeats. I want to see the percentage average on each day up until the order date. For instance if ship_date 2018-07-01 has a total of 100 orders and ship_date 2018-08-01 has a total of 200, then I want to see how much percentage wise on average was ordered 54 days prior to ship_date.
Thanks.
python pandas average
Not quite sure I understand. difference_in_days is equal to what?
– DerrickAtWork
Nov 19 '18 at 22:02
average on days remaining
equal to what? Where is yourdays remaining
column?
– Ken Dekalb
Nov 19 '18 at 22:03
What have you tried so far, and what was the output :)
– Evan
Nov 19 '18 at 22:03
add a comment |
I have a data set, where I'm trying to get an average on days remaining that are equal.
Example:
ship_date Order_date cumulative_ordered days_remaining
2018-07-01 2018-05-06 7 56 days
2018-07-01 2018-05-07 10 55 days
2018-07-01 2018-05-08 15 54 days
The order_date will count down until it reaches the ship_date. by that time the cumulative order equals the total orders up until the shipping date. Then a new ship_date and the process repeats. I want to see the percentage average on each day up until the order date. For instance if ship_date 2018-07-01 has a total of 100 orders and ship_date 2018-08-01 has a total of 200, then I want to see how much percentage wise on average was ordered 54 days prior to ship_date.
Thanks.
python pandas average
I have a data set, where I'm trying to get an average on days remaining that are equal.
Example:
ship_date Order_date cumulative_ordered days_remaining
2018-07-01 2018-05-06 7 56 days
2018-07-01 2018-05-07 10 55 days
2018-07-01 2018-05-08 15 54 days
The order_date will count down until it reaches the ship_date. by that time the cumulative order equals the total orders up until the shipping date. Then a new ship_date and the process repeats. I want to see the percentage average on each day up until the order date. For instance if ship_date 2018-07-01 has a total of 100 orders and ship_date 2018-08-01 has a total of 200, then I want to see how much percentage wise on average was ordered 54 days prior to ship_date.
Thanks.
python pandas average
python pandas average
edited Nov 19 '18 at 22:34
Clueless
asked Nov 19 '18 at 21:59
CluelessClueless
415
415
Not quite sure I understand. difference_in_days is equal to what?
– DerrickAtWork
Nov 19 '18 at 22:02
average on days remaining
equal to what? Where is yourdays remaining
column?
– Ken Dekalb
Nov 19 '18 at 22:03
What have you tried so far, and what was the output :)
– Evan
Nov 19 '18 at 22:03
add a comment |
Not quite sure I understand. difference_in_days is equal to what?
– DerrickAtWork
Nov 19 '18 at 22:02
average on days remaining
equal to what? Where is yourdays remaining
column?
– Ken Dekalb
Nov 19 '18 at 22:03
What have you tried so far, and what was the output :)
– Evan
Nov 19 '18 at 22:03
Not quite sure I understand. difference_in_days is equal to what?
– DerrickAtWork
Nov 19 '18 at 22:02
Not quite sure I understand. difference_in_days is equal to what?
– DerrickAtWork
Nov 19 '18 at 22:02
average on days remaining
equal to what? Where is your days remaining
column?– Ken Dekalb
Nov 19 '18 at 22:03
average on days remaining
equal to what? Where is your days remaining
column?– Ken Dekalb
Nov 19 '18 at 22:03
What have you tried so far, and what was the output :)
– Evan
Nov 19 '18 at 22:03
What have you tried so far, and what was the output :)
– Evan
Nov 19 '18 at 22:03
add a comment |
1 Answer
1
active
oldest
votes
You can obtain the average of total_ordered
per difference_in_days
using groupby:
df.groupby("difference_in_days")['total_ordered'].mean()
This returns a Series with the total_ordered
average per each group of rows with some specific difference_in_days
for example:
difference_in_days
2 days 10.5
56 days 50.22
...
Name: total_ordered, dtype: float64
In order to extract one of the mean values from that Series, you need to assign it to a variable and use the index. Say you want the average of total_ordered
for rows with difference_in_days
equal to 56
, you should do:
g = df.groupby("difference_in_days")['total_ordered'].mean()
# value is the average total_ordered for rows with 56 days of difference.
value = g[g.index.days == 56].iloc[0]
Thanks so much @julianPeller! I changed value to: 'value = g/g[g.index.days == 0].iloc[0]' This is to get the percentage completed order per date. I'm then trying to merge this into a new csv file to create a forecast for cumulative_ordered. Any suggestions how to do that, cause what I have tried is not working. I've added 'diff' to the other file and tried to merge on that...
– Clueless
Nov 21 '18 at 21:12
add a comment |
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%2f53383245%2ffinding-average-on-equal-days-using-pandas%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
You can obtain the average of total_ordered
per difference_in_days
using groupby:
df.groupby("difference_in_days")['total_ordered'].mean()
This returns a Series with the total_ordered
average per each group of rows with some specific difference_in_days
for example:
difference_in_days
2 days 10.5
56 days 50.22
...
Name: total_ordered, dtype: float64
In order to extract one of the mean values from that Series, you need to assign it to a variable and use the index. Say you want the average of total_ordered
for rows with difference_in_days
equal to 56
, you should do:
g = df.groupby("difference_in_days")['total_ordered'].mean()
# value is the average total_ordered for rows with 56 days of difference.
value = g[g.index.days == 56].iloc[0]
Thanks so much @julianPeller! I changed value to: 'value = g/g[g.index.days == 0].iloc[0]' This is to get the percentage completed order per date. I'm then trying to merge this into a new csv file to create a forecast for cumulative_ordered. Any suggestions how to do that, cause what I have tried is not working. I've added 'diff' to the other file and tried to merge on that...
– Clueless
Nov 21 '18 at 21:12
add a comment |
You can obtain the average of total_ordered
per difference_in_days
using groupby:
df.groupby("difference_in_days")['total_ordered'].mean()
This returns a Series with the total_ordered
average per each group of rows with some specific difference_in_days
for example:
difference_in_days
2 days 10.5
56 days 50.22
...
Name: total_ordered, dtype: float64
In order to extract one of the mean values from that Series, you need to assign it to a variable and use the index. Say you want the average of total_ordered
for rows with difference_in_days
equal to 56
, you should do:
g = df.groupby("difference_in_days")['total_ordered'].mean()
# value is the average total_ordered for rows with 56 days of difference.
value = g[g.index.days == 56].iloc[0]
Thanks so much @julianPeller! I changed value to: 'value = g/g[g.index.days == 0].iloc[0]' This is to get the percentage completed order per date. I'm then trying to merge this into a new csv file to create a forecast for cumulative_ordered. Any suggestions how to do that, cause what I have tried is not working. I've added 'diff' to the other file and tried to merge on that...
– Clueless
Nov 21 '18 at 21:12
add a comment |
You can obtain the average of total_ordered
per difference_in_days
using groupby:
df.groupby("difference_in_days")['total_ordered'].mean()
This returns a Series with the total_ordered
average per each group of rows with some specific difference_in_days
for example:
difference_in_days
2 days 10.5
56 days 50.22
...
Name: total_ordered, dtype: float64
In order to extract one of the mean values from that Series, you need to assign it to a variable and use the index. Say you want the average of total_ordered
for rows with difference_in_days
equal to 56
, you should do:
g = df.groupby("difference_in_days")['total_ordered'].mean()
# value is the average total_ordered for rows with 56 days of difference.
value = g[g.index.days == 56].iloc[0]
You can obtain the average of total_ordered
per difference_in_days
using groupby:
df.groupby("difference_in_days")['total_ordered'].mean()
This returns a Series with the total_ordered
average per each group of rows with some specific difference_in_days
for example:
difference_in_days
2 days 10.5
56 days 50.22
...
Name: total_ordered, dtype: float64
In order to extract one of the mean values from that Series, you need to assign it to a variable and use the index. Say you want the average of total_ordered
for rows with difference_in_days
equal to 56
, you should do:
g = df.groupby("difference_in_days")['total_ordered'].mean()
# value is the average total_ordered for rows with 56 days of difference.
value = g[g.index.days == 56].iloc[0]
answered Nov 19 '18 at 22:15
Julian PellerJulian Peller
8941511
8941511
Thanks so much @julianPeller! I changed value to: 'value = g/g[g.index.days == 0].iloc[0]' This is to get the percentage completed order per date. I'm then trying to merge this into a new csv file to create a forecast for cumulative_ordered. Any suggestions how to do that, cause what I have tried is not working. I've added 'diff' to the other file and tried to merge on that...
– Clueless
Nov 21 '18 at 21:12
add a comment |
Thanks so much @julianPeller! I changed value to: 'value = g/g[g.index.days == 0].iloc[0]' This is to get the percentage completed order per date. I'm then trying to merge this into a new csv file to create a forecast for cumulative_ordered. Any suggestions how to do that, cause what I have tried is not working. I've added 'diff' to the other file and tried to merge on that...
– Clueless
Nov 21 '18 at 21:12
Thanks so much @julianPeller! I changed value to: 'value = g/g[g.index.days == 0].iloc[0]' This is to get the percentage completed order per date. I'm then trying to merge this into a new csv file to create a forecast for cumulative_ordered. Any suggestions how to do that, cause what I have tried is not working. I've added 'diff' to the other file and tried to merge on that...
– Clueless
Nov 21 '18 at 21:12
Thanks so much @julianPeller! I changed value to: 'value = g/g[g.index.days == 0].iloc[0]' This is to get the percentage completed order per date. I'm then trying to merge this into a new csv file to create a forecast for cumulative_ordered. Any suggestions how to do that, cause what I have tried is not working. I've added 'diff' to the other file and tried to merge on that...
– Clueless
Nov 21 '18 at 21:12
add a comment |
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%2f53383245%2ffinding-average-on-equal-days-using-pandas%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
Not quite sure I understand. difference_in_days is equal to what?
– DerrickAtWork
Nov 19 '18 at 22:02
average on days remaining
equal to what? Where is yourdays remaining
column?– Ken Dekalb
Nov 19 '18 at 22:03
What have you tried so far, and what was the output :)
– Evan
Nov 19 '18 at 22:03