n days back average for each day Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Moderator Election Q&A - Questionnaire 2019 Community Moderator Election ResultsHow to implement accurate counts or sums when you have different numbers of days of the week?Summary statistics by category using Pythonhow can i sum first day value of each id together?calculate distance between each data point of a cluster to their respective cluster centroidsCreate price matrix from tidy data without for loopHow to scatter plot with each dimension having its own colorReduce number of vectors in dataset to achieve the “same average dimensions result”?python calculating degree daysHow to extract numerical data from a matplotlib scatter plot in python?SVR is giving same prediction for all features
What is a fractional matching?
How come Sam didn't become Lord of Horn Hill?
Did MS DOS itself ever use blinking text?
Is this homebrew Lady of Pain warlock patron balanced?
Can family of EU Blue Card holder travel freely in the Schengen Area with a German Aufenthaltstitel?
Can anything be seen from the center of the Boötes void? How dark would it be?
Is it a good idea to use CNN to classify 1D signal?
How often does castling occur in grandmaster games?
Are all finite dimensional hilbert spaces isomorphic to spaces with Euclidean norms?
How fail-safe is nr as stop bytes?
Is it possible to add Lighting Web Component in the Visual force Page?
NumericArray versus PackedArray in MMA12
AppleTVs create a chatty alternate WiFi network
Can you use the Shield Master feat to shove someone before you make an attack by using a Readied action?
Time to Settle Down!
If windows 7 doesn't support WSL, then what does Linux subsystem option mean?
Crossing US/Canada Border for less than 24 hours
How to convince students of the implication truth values?
Can an alien society believe that their star system is the universe?
Denied boarding although I have proper visa and documentation. To whom should I make a complaint?
Has negative voting ever been officially implemented in elections, or seriously proposed, or even studied?
Is there any word for a place full of confusion?
How does the math work when buying airline miles?
Why is it faster to reheat something than it is to cook it?
n days back average for each day
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Moderator Election Q&A - Questionnaire
2019 Community Moderator Election ResultsHow to implement accurate counts or sums when you have different numbers of days of the week?Summary statistics by category using Pythonhow can i sum first day value of each id together?calculate distance between each data point of a cluster to their respective cluster centroidsCreate price matrix from tidy data without for loopHow to scatter plot with each dimension having its own colorReduce number of vectors in dataset to achieve the “same average dimensions result”?python calculating degree daysHow to extract numerical data from a matplotlib scatter plot in python?SVR is giving same prediction for all features
$begingroup$
I have a dataset as below and I want to see 3 days high low average, back from for each day in the same plot.
index closed high low open
tarih
2018-05-18 1364 0.00000442 0.00000445 0.00000405 0.00000416
2018-05-19 1365 0.00000458 0.00000465 0.00000427 0.00000442
2018-05-20 1366 0.00000482 0.00000489 0.00000448 0.00000455
2018-05-21 1367 0.00000489 0.00000492 0.00000463 0.00000482
2018-05-22 1368 0.00000475 0.00000492 0.00000465 0.00000487
2018-05-23 1369 0.00000461 0.00000486 0.00000450 0.00000475
2018-05-24 1370 0.00000462 0.00000480 0.00000455 0.00000464
for example for 05-24 it will calculate 21,22,23 days high low average and point it to 05-24.
python pandas matplotlib
$endgroup$
add a comment |
$begingroup$
I have a dataset as below and I want to see 3 days high low average, back from for each day in the same plot.
index closed high low open
tarih
2018-05-18 1364 0.00000442 0.00000445 0.00000405 0.00000416
2018-05-19 1365 0.00000458 0.00000465 0.00000427 0.00000442
2018-05-20 1366 0.00000482 0.00000489 0.00000448 0.00000455
2018-05-21 1367 0.00000489 0.00000492 0.00000463 0.00000482
2018-05-22 1368 0.00000475 0.00000492 0.00000465 0.00000487
2018-05-23 1369 0.00000461 0.00000486 0.00000450 0.00000475
2018-05-24 1370 0.00000462 0.00000480 0.00000455 0.00000464
for example for 05-24 it will calculate 21,22,23 days high low average and point it to 05-24.
python pandas matplotlib
$endgroup$
$begingroup$
What you're looking for is called a rolling mean. With a bit of work it is easy to find.
$endgroup$
– Boondoggle
May 24 '18 at 11:49
$begingroup$
If you are using Python, the Pandas library has in-built methods for the rolling mean computation. You have to create a dataFrame with your data
$endgroup$
– ignatius
Apr 3 at 6:34
$begingroup$
Take a look here stackoverflow.com/questions/43437657/…
$endgroup$
– bkshi
Apr 3 at 6:48
add a comment |
$begingroup$
I have a dataset as below and I want to see 3 days high low average, back from for each day in the same plot.
index closed high low open
tarih
2018-05-18 1364 0.00000442 0.00000445 0.00000405 0.00000416
2018-05-19 1365 0.00000458 0.00000465 0.00000427 0.00000442
2018-05-20 1366 0.00000482 0.00000489 0.00000448 0.00000455
2018-05-21 1367 0.00000489 0.00000492 0.00000463 0.00000482
2018-05-22 1368 0.00000475 0.00000492 0.00000465 0.00000487
2018-05-23 1369 0.00000461 0.00000486 0.00000450 0.00000475
2018-05-24 1370 0.00000462 0.00000480 0.00000455 0.00000464
for example for 05-24 it will calculate 21,22,23 days high low average and point it to 05-24.
python pandas matplotlib
$endgroup$
I have a dataset as below and I want to see 3 days high low average, back from for each day in the same plot.
index closed high low open
tarih
2018-05-18 1364 0.00000442 0.00000445 0.00000405 0.00000416
2018-05-19 1365 0.00000458 0.00000465 0.00000427 0.00000442
2018-05-20 1366 0.00000482 0.00000489 0.00000448 0.00000455
2018-05-21 1367 0.00000489 0.00000492 0.00000463 0.00000482
2018-05-22 1368 0.00000475 0.00000492 0.00000465 0.00000487
2018-05-23 1369 0.00000461 0.00000486 0.00000450 0.00000475
2018-05-24 1370 0.00000462 0.00000480 0.00000455 0.00000464
for example for 05-24 it will calculate 21,22,23 days high low average and point it to 05-24.
python pandas matplotlib
python pandas matplotlib
edited Apr 3 at 6:09
Tasos
1,59011138
1,59011138
asked May 24 '18 at 11:44
ChunkBMBChunkBMB
111
111
$begingroup$
What you're looking for is called a rolling mean. With a bit of work it is easy to find.
$endgroup$
– Boondoggle
May 24 '18 at 11:49
$begingroup$
If you are using Python, the Pandas library has in-built methods for the rolling mean computation. You have to create a dataFrame with your data
$endgroup$
– ignatius
Apr 3 at 6:34
$begingroup$
Take a look here stackoverflow.com/questions/43437657/…
$endgroup$
– bkshi
Apr 3 at 6:48
add a comment |
$begingroup$
What you're looking for is called a rolling mean. With a bit of work it is easy to find.
$endgroup$
– Boondoggle
May 24 '18 at 11:49
$begingroup$
If you are using Python, the Pandas library has in-built methods for the rolling mean computation. You have to create a dataFrame with your data
$endgroup$
– ignatius
Apr 3 at 6:34
$begingroup$
Take a look here stackoverflow.com/questions/43437657/…
$endgroup$
– bkshi
Apr 3 at 6:48
$begingroup$
What you're looking for is called a rolling mean. With a bit of work it is easy to find.
$endgroup$
– Boondoggle
May 24 '18 at 11:49
$begingroup$
What you're looking for is called a rolling mean. With a bit of work it is easy to find.
$endgroup$
– Boondoggle
May 24 '18 at 11:49
$begingroup$
If you are using Python, the Pandas library has in-built methods for the rolling mean computation. You have to create a dataFrame with your data
$endgroup$
– ignatius
Apr 3 at 6:34
$begingroup$
If you are using Python, the Pandas library has in-built methods for the rolling mean computation. You have to create a dataFrame with your data
$endgroup$
– ignatius
Apr 3 at 6:34
$begingroup$
Take a look here stackoverflow.com/questions/43437657/…
$endgroup$
– bkshi
Apr 3 at 6:48
$begingroup$
Take a look here stackoverflow.com/questions/43437657/…
$endgroup$
– bkshi
Apr 3 at 6:48
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
You can use the pandas rolling method for that.
back = 3
cols = ['high','low']
# calculate rolling mean on the dataframe's columns of interest
df_back_average = df[cols].rolling(back).mean()
# rename columns before concatenating the result back
df_back_average.columns = str(back) + '_back_average_' + df_back_average.columns
pd.concat([df[cols],df_back_average], axis=1)
high low 3_back_average_high 3_back_average_low
0.000442 0.000445 NaN NaN
0.004580 0.004650 NaN NaN
0.004820 0.004890 0.003281 0.003328
0.004890 0.004920 0.004763 0.004820
0.004750 0.004920 0.004820 0.004910
0.004610 0.004860 0.004750 0.004900
0.004620 0.004800 0.004660 0.004860
$endgroup$
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "557"
;
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2fdatascience.stackexchange.com%2fquestions%2f32103%2fn-days-back-average-for-each-day%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
$begingroup$
You can use the pandas rolling method for that.
back = 3
cols = ['high','low']
# calculate rolling mean on the dataframe's columns of interest
df_back_average = df[cols].rolling(back).mean()
# rename columns before concatenating the result back
df_back_average.columns = str(back) + '_back_average_' + df_back_average.columns
pd.concat([df[cols],df_back_average], axis=1)
high low 3_back_average_high 3_back_average_low
0.000442 0.000445 NaN NaN
0.004580 0.004650 NaN NaN
0.004820 0.004890 0.003281 0.003328
0.004890 0.004920 0.004763 0.004820
0.004750 0.004920 0.004820 0.004910
0.004610 0.004860 0.004750 0.004900
0.004620 0.004800 0.004660 0.004860
$endgroup$
add a comment |
$begingroup$
You can use the pandas rolling method for that.
back = 3
cols = ['high','low']
# calculate rolling mean on the dataframe's columns of interest
df_back_average = df[cols].rolling(back).mean()
# rename columns before concatenating the result back
df_back_average.columns = str(back) + '_back_average_' + df_back_average.columns
pd.concat([df[cols],df_back_average], axis=1)
high low 3_back_average_high 3_back_average_low
0.000442 0.000445 NaN NaN
0.004580 0.004650 NaN NaN
0.004820 0.004890 0.003281 0.003328
0.004890 0.004920 0.004763 0.004820
0.004750 0.004920 0.004820 0.004910
0.004610 0.004860 0.004750 0.004900
0.004620 0.004800 0.004660 0.004860
$endgroup$
add a comment |
$begingroup$
You can use the pandas rolling method for that.
back = 3
cols = ['high','low']
# calculate rolling mean on the dataframe's columns of interest
df_back_average = df[cols].rolling(back).mean()
# rename columns before concatenating the result back
df_back_average.columns = str(back) + '_back_average_' + df_back_average.columns
pd.concat([df[cols],df_back_average], axis=1)
high low 3_back_average_high 3_back_average_low
0.000442 0.000445 NaN NaN
0.004580 0.004650 NaN NaN
0.004820 0.004890 0.003281 0.003328
0.004890 0.004920 0.004763 0.004820
0.004750 0.004920 0.004820 0.004910
0.004610 0.004860 0.004750 0.004900
0.004620 0.004800 0.004660 0.004860
$endgroup$
You can use the pandas rolling method for that.
back = 3
cols = ['high','low']
# calculate rolling mean on the dataframe's columns of interest
df_back_average = df[cols].rolling(back).mean()
# rename columns before concatenating the result back
df_back_average.columns = str(back) + '_back_average_' + df_back_average.columns
pd.concat([df[cols],df_back_average], axis=1)
high low 3_back_average_high 3_back_average_low
0.000442 0.000445 NaN NaN
0.004580 0.004650 NaN NaN
0.004820 0.004890 0.003281 0.003328
0.004890 0.004920 0.004763 0.004820
0.004750 0.004920 0.004820 0.004910
0.004610 0.004860 0.004750 0.004900
0.004620 0.004800 0.004660 0.004860
answered Apr 11 at 13:02
RomidRomid
511
511
add a comment |
add a comment |
Thanks for contributing an answer to Data Science Stack Exchange!
- 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.
Use MathJax to format equations. MathJax reference.
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%2fdatascience.stackexchange.com%2fquestions%2f32103%2fn-days-back-average-for-each-day%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
$begingroup$
What you're looking for is called a rolling mean. With a bit of work it is easy to find.
$endgroup$
– Boondoggle
May 24 '18 at 11:49
$begingroup$
If you are using Python, the Pandas library has in-built methods for the rolling mean computation. You have to create a dataFrame with your data
$endgroup$
– ignatius
Apr 3 at 6:34
$begingroup$
Take a look here stackoverflow.com/questions/43437657/…
$endgroup$
– bkshi
Apr 3 at 6:48