Finding average on equal days using pandas












0















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.










share|improve this question

























  • 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













  • What have you tried so far, and what was the output :)

    – Evan
    Nov 19 '18 at 22:03
















0















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.










share|improve this question

























  • 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













  • What have you tried so far, and what was the output :)

    – Evan
    Nov 19 '18 at 22:03














0












0








0








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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



















  • 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













  • 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












1 Answer
1






active

oldest

votes


















1














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]





share|improve this answer
























  • 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













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%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









1














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]





share|improve this answer
























  • 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


















1














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]





share|improve this answer
























  • 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
















1












1








1







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]





share|improve this answer













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]






share|improve this answer












share|improve this answer



share|improve this answer










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





















  • 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






















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%2f53383245%2ffinding-average-on-equal-days-using-pandas%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

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)