find average in remaining days using python pandas
up vote
0
down vote
favorite
df is a csv file that contains ship_date, order_date and cumulative_ordered. cumulative_ordered is the sum of orders added on every day up until ship_date. There are 30 days prior to every ship_date and those days only counts for one ship_date. after ship_date 2018-07-01, then next ship_date will be 2018-08-01 with same procedure.
My problem is that I can't get days remaining(see last code output below) when I calculate the percentage average of cumulative_ordered on each of those 30 days prior.
I have the following code, that gives me the days_remaining from a csv file with several different ship_date and order_date counting down to each separate ship_date.
df['days_remaining'] = pd.to_datetime(df['ship_date']).sub
(pd.to_datetime(df['order_date'])).dt.days
df['difference'] = df['ship_date'] - df['order_date']
df.head()
output:
ship_date Order_date cumulative_ordered days_remaining difference
2018-07-01 2018-06-01 7 30 30 days
2018-07-01 2018-06-02 10 29 29 days
2018-07-01 2018-06-03 15 28 28 days
2018-07-01 2018-06-04 30 28 27 days
2018-07-01 2018-06-05 41 28 26 days
I then try to find total ordered on each day prior to ship_date
m = df.groupby("difference").mean()
m.head()
which gives me this output:
cumulative ordered days_remaining
difference
0 days 352.458124 0.0
1 days 291.234747 1.0
2 days 244.122137 2.0
3 days 201.178765 3.0
4 days 190.153641 4.0
I'm running into an issue when I try to find an average of cumulative ordered on each day in terms of percentage filled from cumulative_ordered output on 0 days above, by running this code:
v = m/m[m.index.days == 0].iloc[0]
v.head()
cumulative_ordered days_remaining
difference
0 days 1.000000 NaN
1 days 0.891324 inf
2 days 0.812534 inf
3 days 0.752339 inf
4 days 0.673745 inf
days_remaining changes to NaN and inf.. How can I keep it so it still gives me integers?
python pandas dataframe percentage
add a comment |
up vote
0
down vote
favorite
df is a csv file that contains ship_date, order_date and cumulative_ordered. cumulative_ordered is the sum of orders added on every day up until ship_date. There are 30 days prior to every ship_date and those days only counts for one ship_date. after ship_date 2018-07-01, then next ship_date will be 2018-08-01 with same procedure.
My problem is that I can't get days remaining(see last code output below) when I calculate the percentage average of cumulative_ordered on each of those 30 days prior.
I have the following code, that gives me the days_remaining from a csv file with several different ship_date and order_date counting down to each separate ship_date.
df['days_remaining'] = pd.to_datetime(df['ship_date']).sub
(pd.to_datetime(df['order_date'])).dt.days
df['difference'] = df['ship_date'] - df['order_date']
df.head()
output:
ship_date Order_date cumulative_ordered days_remaining difference
2018-07-01 2018-06-01 7 30 30 days
2018-07-01 2018-06-02 10 29 29 days
2018-07-01 2018-06-03 15 28 28 days
2018-07-01 2018-06-04 30 28 27 days
2018-07-01 2018-06-05 41 28 26 days
I then try to find total ordered on each day prior to ship_date
m = df.groupby("difference").mean()
m.head()
which gives me this output:
cumulative ordered days_remaining
difference
0 days 352.458124 0.0
1 days 291.234747 1.0
2 days 244.122137 2.0
3 days 201.178765 3.0
4 days 190.153641 4.0
I'm running into an issue when I try to find an average of cumulative ordered on each day in terms of percentage filled from cumulative_ordered output on 0 days above, by running this code:
v = m/m[m.index.days == 0].iloc[0]
v.head()
cumulative_ordered days_remaining
difference
0 days 1.000000 NaN
1 days 0.891324 inf
2 days 0.812534 inf
3 days 0.752339 inf
4 days 0.673745 inf
days_remaining changes to NaN and inf.. How can I keep it so it still gives me integers?
python pandas dataframe percentage
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
df is a csv file that contains ship_date, order_date and cumulative_ordered. cumulative_ordered is the sum of orders added on every day up until ship_date. There are 30 days prior to every ship_date and those days only counts for one ship_date. after ship_date 2018-07-01, then next ship_date will be 2018-08-01 with same procedure.
My problem is that I can't get days remaining(see last code output below) when I calculate the percentage average of cumulative_ordered on each of those 30 days prior.
I have the following code, that gives me the days_remaining from a csv file with several different ship_date and order_date counting down to each separate ship_date.
df['days_remaining'] = pd.to_datetime(df['ship_date']).sub
(pd.to_datetime(df['order_date'])).dt.days
df['difference'] = df['ship_date'] - df['order_date']
df.head()
output:
ship_date Order_date cumulative_ordered days_remaining difference
2018-07-01 2018-06-01 7 30 30 days
2018-07-01 2018-06-02 10 29 29 days
2018-07-01 2018-06-03 15 28 28 days
2018-07-01 2018-06-04 30 28 27 days
2018-07-01 2018-06-05 41 28 26 days
I then try to find total ordered on each day prior to ship_date
m = df.groupby("difference").mean()
m.head()
which gives me this output:
cumulative ordered days_remaining
difference
0 days 352.458124 0.0
1 days 291.234747 1.0
2 days 244.122137 2.0
3 days 201.178765 3.0
4 days 190.153641 4.0
I'm running into an issue when I try to find an average of cumulative ordered on each day in terms of percentage filled from cumulative_ordered output on 0 days above, by running this code:
v = m/m[m.index.days == 0].iloc[0]
v.head()
cumulative_ordered days_remaining
difference
0 days 1.000000 NaN
1 days 0.891324 inf
2 days 0.812534 inf
3 days 0.752339 inf
4 days 0.673745 inf
days_remaining changes to NaN and inf.. How can I keep it so it still gives me integers?
python pandas dataframe percentage
df is a csv file that contains ship_date, order_date and cumulative_ordered. cumulative_ordered is the sum of orders added on every day up until ship_date. There are 30 days prior to every ship_date and those days only counts for one ship_date. after ship_date 2018-07-01, then next ship_date will be 2018-08-01 with same procedure.
My problem is that I can't get days remaining(see last code output below) when I calculate the percentage average of cumulative_ordered on each of those 30 days prior.
I have the following code, that gives me the days_remaining from a csv file with several different ship_date and order_date counting down to each separate ship_date.
df['days_remaining'] = pd.to_datetime(df['ship_date']).sub
(pd.to_datetime(df['order_date'])).dt.days
df['difference'] = df['ship_date'] - df['order_date']
df.head()
output:
ship_date Order_date cumulative_ordered days_remaining difference
2018-07-01 2018-06-01 7 30 30 days
2018-07-01 2018-06-02 10 29 29 days
2018-07-01 2018-06-03 15 28 28 days
2018-07-01 2018-06-04 30 28 27 days
2018-07-01 2018-06-05 41 28 26 days
I then try to find total ordered on each day prior to ship_date
m = df.groupby("difference").mean()
m.head()
which gives me this output:
cumulative ordered days_remaining
difference
0 days 352.458124 0.0
1 days 291.234747 1.0
2 days 244.122137 2.0
3 days 201.178765 3.0
4 days 190.153641 4.0
I'm running into an issue when I try to find an average of cumulative ordered on each day in terms of percentage filled from cumulative_ordered output on 0 days above, by running this code:
v = m/m[m.index.days == 0].iloc[0]
v.head()
cumulative_ordered days_remaining
difference
0 days 1.000000 NaN
1 days 0.891324 inf
2 days 0.812534 inf
3 days 0.752339 inf
4 days 0.673745 inf
days_remaining changes to NaN and inf.. How can I keep it so it still gives me integers?
python pandas dataframe percentage
python pandas dataframe percentage
asked Nov 21 at 19:49
Clueless
275
275
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
The NaN
and inf
result from dividing by 0.0
.
It seems that you are trying to apply the operation only to the cumulative_ordered
column, so you should just run this for your last block of code:
m['cumulative_ordered'] = m['cumulative_ordered'] / m['cumulative_ordered'][m['cumulative_ordered'].index.days == 0]
Hi, thanks, this is not working because I need the days_remaining column to be able to merge with another csv file and from there make a forecast based on cumulative_ordered average.
– Clueless
Nov 21 at 21:56
What is the desired output fordays_remaining
?
– PJW
Nov 21 at 22:07
no change, just for it to remain the same as above.. counting down the days.. 0,1,2 etc
– Clueless
Nov 21 at 22:15
Yeah, so I thought if you run the line I suggested,days_remaining
would remain unchanged. And if you printm.head()
,cumulative_ordered
would be the only column modified (if you wantdays_remaining
to be integers instead of floats, that is another issue).
– PJW
Nov 21 at 22:26
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
The NaN
and inf
result from dividing by 0.0
.
It seems that you are trying to apply the operation only to the cumulative_ordered
column, so you should just run this for your last block of code:
m['cumulative_ordered'] = m['cumulative_ordered'] / m['cumulative_ordered'][m['cumulative_ordered'].index.days == 0]
Hi, thanks, this is not working because I need the days_remaining column to be able to merge with another csv file and from there make a forecast based on cumulative_ordered average.
– Clueless
Nov 21 at 21:56
What is the desired output fordays_remaining
?
– PJW
Nov 21 at 22:07
no change, just for it to remain the same as above.. counting down the days.. 0,1,2 etc
– Clueless
Nov 21 at 22:15
Yeah, so I thought if you run the line I suggested,days_remaining
would remain unchanged. And if you printm.head()
,cumulative_ordered
would be the only column modified (if you wantdays_remaining
to be integers instead of floats, that is another issue).
– PJW
Nov 21 at 22:26
add a comment |
up vote
1
down vote
accepted
The NaN
and inf
result from dividing by 0.0
.
It seems that you are trying to apply the operation only to the cumulative_ordered
column, so you should just run this for your last block of code:
m['cumulative_ordered'] = m['cumulative_ordered'] / m['cumulative_ordered'][m['cumulative_ordered'].index.days == 0]
Hi, thanks, this is not working because I need the days_remaining column to be able to merge with another csv file and from there make a forecast based on cumulative_ordered average.
– Clueless
Nov 21 at 21:56
What is the desired output fordays_remaining
?
– PJW
Nov 21 at 22:07
no change, just for it to remain the same as above.. counting down the days.. 0,1,2 etc
– Clueless
Nov 21 at 22:15
Yeah, so I thought if you run the line I suggested,days_remaining
would remain unchanged. And if you printm.head()
,cumulative_ordered
would be the only column modified (if you wantdays_remaining
to be integers instead of floats, that is another issue).
– PJW
Nov 21 at 22:26
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
The NaN
and inf
result from dividing by 0.0
.
It seems that you are trying to apply the operation only to the cumulative_ordered
column, so you should just run this for your last block of code:
m['cumulative_ordered'] = m['cumulative_ordered'] / m['cumulative_ordered'][m['cumulative_ordered'].index.days == 0]
The NaN
and inf
result from dividing by 0.0
.
It seems that you are trying to apply the operation only to the cumulative_ordered
column, so you should just run this for your last block of code:
m['cumulative_ordered'] = m['cumulative_ordered'] / m['cumulative_ordered'][m['cumulative_ordered'].index.days == 0]
edited Nov 21 at 21:36
answered Nov 21 at 21:30
PJW
616725
616725
Hi, thanks, this is not working because I need the days_remaining column to be able to merge with another csv file and from there make a forecast based on cumulative_ordered average.
– Clueless
Nov 21 at 21:56
What is the desired output fordays_remaining
?
– PJW
Nov 21 at 22:07
no change, just for it to remain the same as above.. counting down the days.. 0,1,2 etc
– Clueless
Nov 21 at 22:15
Yeah, so I thought if you run the line I suggested,days_remaining
would remain unchanged. And if you printm.head()
,cumulative_ordered
would be the only column modified (if you wantdays_remaining
to be integers instead of floats, that is another issue).
– PJW
Nov 21 at 22:26
add a comment |
Hi, thanks, this is not working because I need the days_remaining column to be able to merge with another csv file and from there make a forecast based on cumulative_ordered average.
– Clueless
Nov 21 at 21:56
What is the desired output fordays_remaining
?
– PJW
Nov 21 at 22:07
no change, just for it to remain the same as above.. counting down the days.. 0,1,2 etc
– Clueless
Nov 21 at 22:15
Yeah, so I thought if you run the line I suggested,days_remaining
would remain unchanged. And if you printm.head()
,cumulative_ordered
would be the only column modified (if you wantdays_remaining
to be integers instead of floats, that is another issue).
– PJW
Nov 21 at 22:26
Hi, thanks, this is not working because I need the days_remaining column to be able to merge with another csv file and from there make a forecast based on cumulative_ordered average.
– Clueless
Nov 21 at 21:56
Hi, thanks, this is not working because I need the days_remaining column to be able to merge with another csv file and from there make a forecast based on cumulative_ordered average.
– Clueless
Nov 21 at 21:56
What is the desired output for
days_remaining
?– PJW
Nov 21 at 22:07
What is the desired output for
days_remaining
?– PJW
Nov 21 at 22:07
no change, just for it to remain the same as above.. counting down the days.. 0,1,2 etc
– Clueless
Nov 21 at 22:15
no change, just for it to remain the same as above.. counting down the days.. 0,1,2 etc
– Clueless
Nov 21 at 22:15
Yeah, so I thought if you run the line I suggested,
days_remaining
would remain unchanged. And if you print m.head()
, cumulative_ordered
would be the only column modified (if you want days_remaining
to be integers instead of floats, that is another issue).– PJW
Nov 21 at 22:26
Yeah, so I thought if you run the line I suggested,
days_remaining
would remain unchanged. And if you print m.head()
, cumulative_ordered
would be the only column modified (if you want days_remaining
to be integers instead of floats, that is another issue).– PJW
Nov 21 at 22:26
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.
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.
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%2f53419542%2ffind-average-in-remaining-days-using-python-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