Create pandas dataframe where each cell basis on slope calculation with time series rows from another df
up vote
2
down vote
favorite
I have a dataframe with about 40 columns and about 100000 rows:
ID MONTH_NUM_
FROM_EVENT F1 F2 F3 F4 etc…
2 1 4.0 133.0 28.0 NaN
2 2 NaN 132.0 29.0 24.0
2 3 NaN 131.0 NaN 29.0
2 4 4.0 130.0 31.0 7.0
2 5 8.0 129.0 26.0 2.0
2 6 8.0 128.0 25.0 3.0
4 1 5.0 139.0 29.0 7.0
4 2 5.0 138.0 NaN 22.0
4 3 5.0 137.0 30.0 28.0
4 4 5.0 136.0 29.0 25.0
4 5 5.0 135.0 NaN 27.0
4 6 5.0 134.0 27.0 29.0
etc…
each columns F is a 6m time series data with NaN for each rows ID client
I want to output new dataframe without monthes like so:
ID F1 F2 F3 F4 etc…
2
4
etc…
where each cell of new data frame is a slope calculation of 6m time series for each F colums with following code example:
x = [6, 5, 4, 3, 2, 1] #its constanta for each calcul, monthes with reverse orders because 1 is last month before event prediction
y = df.F1[df['ID']==2]
xm = np.ma.masked_array(x,mask=np.isnan(y)).compressed() #ignore Nans
ym = np.ma.masked_array(y,mask=np.isnan(y)).compressed() #ignore Nans
from scipy.stats import linregress
linregress(xm, ym).slope
What is the efficient way to looping this calculation and create new df?
Thanx in advance...
python pandas dataframe regression
add a comment |
up vote
2
down vote
favorite
I have a dataframe with about 40 columns and about 100000 rows:
ID MONTH_NUM_
FROM_EVENT F1 F2 F3 F4 etc…
2 1 4.0 133.0 28.0 NaN
2 2 NaN 132.0 29.0 24.0
2 3 NaN 131.0 NaN 29.0
2 4 4.0 130.0 31.0 7.0
2 5 8.0 129.0 26.0 2.0
2 6 8.0 128.0 25.0 3.0
4 1 5.0 139.0 29.0 7.0
4 2 5.0 138.0 NaN 22.0
4 3 5.0 137.0 30.0 28.0
4 4 5.0 136.0 29.0 25.0
4 5 5.0 135.0 NaN 27.0
4 6 5.0 134.0 27.0 29.0
etc…
each columns F is a 6m time series data with NaN for each rows ID client
I want to output new dataframe without monthes like so:
ID F1 F2 F3 F4 etc…
2
4
etc…
where each cell of new data frame is a slope calculation of 6m time series for each F colums with following code example:
x = [6, 5, 4, 3, 2, 1] #its constanta for each calcul, monthes with reverse orders because 1 is last month before event prediction
y = df.F1[df['ID']==2]
xm = np.ma.masked_array(x,mask=np.isnan(y)).compressed() #ignore Nans
ym = np.ma.masked_array(y,mask=np.isnan(y)).compressed() #ignore Nans
from scipy.stats import linregress
linregress(xm, ym).slope
What is the efficient way to looping this calculation and create new df?
Thanx in advance...
python pandas dataframe regression
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I have a dataframe with about 40 columns and about 100000 rows:
ID MONTH_NUM_
FROM_EVENT F1 F2 F3 F4 etc…
2 1 4.0 133.0 28.0 NaN
2 2 NaN 132.0 29.0 24.0
2 3 NaN 131.0 NaN 29.0
2 4 4.0 130.0 31.0 7.0
2 5 8.0 129.0 26.0 2.0
2 6 8.0 128.0 25.0 3.0
4 1 5.0 139.0 29.0 7.0
4 2 5.0 138.0 NaN 22.0
4 3 5.0 137.0 30.0 28.0
4 4 5.0 136.0 29.0 25.0
4 5 5.0 135.0 NaN 27.0
4 6 5.0 134.0 27.0 29.0
etc…
each columns F is a 6m time series data with NaN for each rows ID client
I want to output new dataframe without monthes like so:
ID F1 F2 F3 F4 etc…
2
4
etc…
where each cell of new data frame is a slope calculation of 6m time series for each F colums with following code example:
x = [6, 5, 4, 3, 2, 1] #its constanta for each calcul, monthes with reverse orders because 1 is last month before event prediction
y = df.F1[df['ID']==2]
xm = np.ma.masked_array(x,mask=np.isnan(y)).compressed() #ignore Nans
ym = np.ma.masked_array(y,mask=np.isnan(y)).compressed() #ignore Nans
from scipy.stats import linregress
linregress(xm, ym).slope
What is the efficient way to looping this calculation and create new df?
Thanx in advance...
python pandas dataframe regression
I have a dataframe with about 40 columns and about 100000 rows:
ID MONTH_NUM_
FROM_EVENT F1 F2 F3 F4 etc…
2 1 4.0 133.0 28.0 NaN
2 2 NaN 132.0 29.0 24.0
2 3 NaN 131.0 NaN 29.0
2 4 4.0 130.0 31.0 7.0
2 5 8.0 129.0 26.0 2.0
2 6 8.0 128.0 25.0 3.0
4 1 5.0 139.0 29.0 7.0
4 2 5.0 138.0 NaN 22.0
4 3 5.0 137.0 30.0 28.0
4 4 5.0 136.0 29.0 25.0
4 5 5.0 135.0 NaN 27.0
4 6 5.0 134.0 27.0 29.0
etc…
each columns F is a 6m time series data with NaN for each rows ID client
I want to output new dataframe without monthes like so:
ID F1 F2 F3 F4 etc…
2
4
etc…
where each cell of new data frame is a slope calculation of 6m time series for each F colums with following code example:
x = [6, 5, 4, 3, 2, 1] #its constanta for each calcul, monthes with reverse orders because 1 is last month before event prediction
y = df.F1[df['ID']==2]
xm = np.ma.masked_array(x,mask=np.isnan(y)).compressed() #ignore Nans
ym = np.ma.masked_array(y,mask=np.isnan(y)).compressed() #ignore Nans
from scipy.stats import linregress
linregress(xm, ym).slope
What is the efficient way to looping this calculation and create new df?
Thanx in advance...
python pandas dataframe regression
python pandas dataframe regression
edited Nov 22 at 9:12
asked Nov 21 at 14:27
Jungleman Jungleman
112
112
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f53414261%2fcreate-pandas-dataframe-where-each-cell-basis-on-slope-calculation-with-time-ser%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