Questions tagged [rolling-average]
104 questions
14
votes
2 answers
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 …

Thomas
- 141
- 1
- 1
- 5
8
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,
…

RmyjuloR
- 369
- 1
- 4
- 13
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…

Laura Diemer
- 73
- 2
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
: …

Makoto Miyazaki
- 1,743
- 2
- 23
- 39
6
votes
2 answers
pandas rolling window mean in the future
I would like to use the pandas.DataFrame.rolling method on a data frame with datetime to aggregate future values.
It looks it can be done only in the past, is it correct?

user1403546
- 1,680
- 4
- 22
- 43
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 …

karen
- 822
- 1
- 6
- 22
4
votes
2 answers
Calculating a rolling 14 day average when dates are missing
I need to calculate the rolling 14 day average for a large data set. The data set is private, although I can share a small snippet.
The data set comes from an instrument in the field which does not operate every day. For instance, a snippet of the…

Deez
- 89
- 6
4
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…

Pepin Peng
- 457
- 1
- 8
- 21
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 …

Marco Lau
- 43
- 3
3
votes
2 answers
SQL/BIGQUERY Running Average with GAPs in Dates
I'm having trouble with a moving average in BigQuery/SQL, I have table 'SCORES' and I need to make a 30d moving average while grouping the data using users, the problem is my dates aren't sequential, e.g there are gaps in it.
Below is my current…

bknight
- 85
- 7
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,…

Michelle
- 31
- 1
- 5
2
votes
1 answer
Rolling average of 4 days on Date column with respect to group of 2 other columns in pandas
I am trying to calculate the rolling average of 4 days on the below dataset. The result should also be calculated based on group of 2 other columns.
For example:
df_time = pd.DataFrame({'A': [123, 123, 278, 278, 278, 123, 345, 278, 123,278, 278],
…

TheDS
- 101
- 2
- 11
2
votes
2 answers
How to take one-hour rolling average from a Dataframe in Python with flexible number of readings in each hour?
I want to take a one-hour rolling average from a Dataframe in Python but the problem is the number of readings in each hour is not fixed and I cannot put a constant number in the rolling average function. Below is what my Dataframe looks like:
…

Paul
- 59
- 5
2
votes
1 answer
How to make moving average using geopandas nearest neighbors?
I have a geodataframe ("GDF") with one column as "values", and another column as "geometry" (that in fact are actual geographical regions), so each row represents a region.
The "values" column is zero in many rows, and a large number in some rows.
I…

ElTitoFranki
- 375
- 1
- 7
2
votes
3 answers
how to calculate a moving average in a dataframe?
I have a dataframe column that looks like this:
CurrentCreditLines
0 5.0
1 14.0
2 NaN
3 5.0
4 19.0
with 110k records, how can I calculate the moving average? also I need it to be rounded and with type float, I tried…

Marco Nashaat
- 67
- 6