Questions tagged [rolling-average]
73 questions
11
votes
1 answer
1 Year Rolling mean pandas on column date
I would like to compute the 1-year rolling average for each row in this Dataframe test:
index id date variation
2313 7034 2018-03-14 4.139148e-06
2314 7034 2018-03-13 4.953194e-07
2315 7034 2018-03-12 …
![](../../users/profiles/9523565.webp)
Thomas
- 111
- 1
- 5
7
votes
2 answers
rolling 30-day geometric mean with variable width
The solution to this question by @ShirinYavari was almost what I needed except for the use of the static averaging window width of 2. I have a dataset with random samples from multiple stations that I want to calculate a rolling 30-day geomean. I…
![](../../users/profiles/12859579.webp)
Laura Diemer
- 73
- 2
7
votes
4 answers
r calculating rolling average with window based on value (not number of rows or date/time variable)
I'm quite new to all the packages meant for calculating rolling averages in R and I hope you can show me in the right direction.
I have the following data as an example:
ms <- c(300, 300, 300, 301, 303, 305, 305, 306, 308, 310, 310, 311, 312,
…
![](../../users/profiles/3233153.webp)
RmyjuloR
- 319
- 1
- 3
- 12
6
votes
2 answers
Change rolling window size as it rolls
I have a pandas data frame like this;
>df
leg speed
1 10
1 11
1 12
1 13
1 12
1 15
1 19
1 12
2 10
2 10
2 12
2 15
2 19
2 11
: …
![](../../users/profiles/8876025.webp)
Makoto Miyazaki
- 1,210
- 2
- 10
- 25
6
votes
1 answer
pandas.DataFrame.rolling not working with huge floats
I have an error with pandas rolling when using floats close to infinity. I display an example here:
import pandas as pd
series = pd.Series(1.,index = pd.date_range('2015-01-01', periods=6))
series[series.index[2]] = 1e19
series
2015-01-01 …
![](../../users/profiles/8381897.webp)
karen
- 767
- 5
- 20
4
votes
1 answer
pandas rolling window mean in the future
I would like to use the pandas rolling function
https://pandas.pydata.org/pandas-docs/version/0.22/generated/pandas.DataFrame.rolling.html
on a pandas dataframe with datetime to aggregate future values.
It looks it can be done only in the past, is…
![](../../users/profiles/1403546.webp)
user1403546
- 1,379
- 1
- 16
- 32
3
votes
2 answers
Find running average which equal
Let say I have some data associated with football
Date Home Away HomeGoal AwayGoal TotalGoal
2019 Arsenal MU 5 1 6
2019 MCity Liv 2 2 4
2019 MU Liv 3 4 7
2019 MCity MU …
![](../../users/profiles/9603299.webp)
Marco Lau
- 43
- 3
3
votes
1 answer
Moving average in Pandas
I have a csv file with 3 columns and I want to get the moving average of 1 column.
I want to create a new column with the moving average.
import pandas as pd
df= pd.read_csv('csv',usecols=['speed','col2', 'col3'])
df['MA'] = df.rolling( window=5,…
![](../../users/profiles/9968506.webp)
Michelle
- 31
- 1
- 5
3
votes
4 answers
How to fill first N/A cell when apply rolling mean to a column -python
I need to apply rolling mean to a column as showing in pic1 s3, after i apply rolling mean and set windows = 5, i got correct answer , but left first 4 rows empty,as showing in pic2 sa3.
i want to fill the first 4 empty cells in pic2 sa3 with the…
![](../../users/profiles/8952552.webp)
Pepin Peng
- 415
- 1
- 6
- 19
2
votes
1 answer
Mean between n and n+1 row in pandas groupby object?
I have a groupby object:
col1 col2 x y z
0 A D1 0.269002 0.131740 0.401020
1 B D1 0.201159 0.072912 0.775171
2 D D1 0.745292 0.725807 0.106000
3 F D1 0.270844 0.214708 0.935534
4 C D1 …
![](../../users/profiles/6293431.webp)
James
- 256
- 4
- 12
1
vote
1 answer
Calculating Moving Average of a column based on values of another column in a dataframe Python (Pandas)
I am trying to create a column of the 10-day moving average of points for nba players. My dataframe has game by game statistics for each player, and I would like to have the moving average column contain the 10 day moving average at that point. I…
![](../../users/profiles/15586267.webp)
Steven Miller
- 31
- 3
1
vote
2 answers
Performing a rolling average with criteria in R
Been trying to learn the most basic of items at first and then expanding the complexity. So for this one, how would I modify the last line to where it would be create a rolling 12 month average for each seriescode. In this case, it would produce an…
![](../../users/profiles/4578075.webp)
Tim Wilcox
- 699
- 1
- 9
- 28
1
vote
2 answers
Create rolling average in dataframe until a set point
I have a dataframe like this:
month val1 val2 val3
1 2 3 5
2 3 4 7
3 5 1 2
4 7 4 3
5 2 6 4
6 2 2 2
The last month in my initial column is 6 here, but could be anything from month 1…
![](../../users/profiles/10717664.webp)
Arlowest
- 35
- 4
1
vote
2 answers
Rolling max excluding current observation in Pandas 1.0
Using Pandas 1.0 I need to generate a rolling max with a window of the previous 3 observations, excluding the current observation. In R this is achieved by
library(tidyverse)
test_df = data.frame(a = 1:5, b = c(40, 37, 60, 45, 40))
test_df <-…
![](../../users/profiles/2515265.webp)
Javide
- 2,069
- 2
- 34
- 52
1
vote
1 answer
Rolling Average in sqlite
I want to calculate a rolling average in a table and keep track of the starting time of each calculated window frame.
My problem is, that I expect result count reduced compared of the rows in the table. But my query retuns the exact same row…
![](../../users/profiles/4634044.webp)
ChristianMurschall
- 1,447
- 10
- 20