Questions tagged [rolling-computation]

A rolling computation is a computation applied to a moving window.

A rolling computation is a computation applied to a moving window, usually where the individual windows overlap as the window moves over the domain.

For example, a Moving Average is a very popular rolling computation.

See also:

1056 questions
226
votes
19 answers

How to calculate rolling / moving average using python + NumPy / SciPy?

There seems to be no function that simply calculates the moving average on numpy/scipy, leading to convoluted solutions. My question is two-fold: What's the easiest way to (correctly) implement a moving average with numpy? Since this seems…
loopbackbee
  • 21,962
  • 10
  • 62
  • 97
118
votes
9 answers

Pandas: rolling mean by time interval

I've got a bunch of polling data; I want to compute a Pandas rolling mean to get an estimate for each day based on a three-day window. According to this question, the rolling_* functions compute the window based on a specified number of values, and…
Anov
  • 2,272
  • 2
  • 20
  • 26
86
votes
5 answers

Python - rolling functions for GroupBy object

I have a time series object grouped of the type . grouped.sum() gives the desired result but I cannot get rolling_sum to work with the groupby object. Is there any way to apply rolling…
user1642513
36
votes
6 answers

Pandas rolling apply using multiple columns

I am trying to use a pandas.DataFrame.rolling.apply() rolling function on multiple columns. Python version is 3.7, pandas is 1.0.2. import pandas as pd #function to calculate def masscenter(x): print(x); # for debug purposes return…
Suthiro
  • 1,210
  • 1
  • 7
  • 18
22
votes
6 answers

How do I calculate a running SUM?

How do I get a column that is the sum of the preceding values of another column?
Hugo
  • 1,558
  • 12
  • 35
  • 68
21
votes
6 answers

Sum values in a rolling/sliding window

I have the following vector: x = c(1, 2, 3, 10, 20, 30) At each index, 3 consecutive elements are summed, resulting in the following vector: c(6, 15, 33, 60) Thus, first element is 1 + 2 + 3 = 6, the second element is 2 + 3 + 10 = 15, et.c
user2834313
  • 213
  • 1
  • 2
  • 6
18
votes
3 answers

Adaptive moving average - top performance in R

I am looking for some performance gains in terms of rolling/sliding window functions in R. It is quite common task which can be used in any ordered observations data set. I would like to share some of my findings, maybe somebody would be able to…
jangorecki
  • 16,384
  • 4
  • 79
  • 160
16
votes
5 answers

Query for count of distinct values in a rolling date range

I have a data set of email addresses and dates that those email addresses were added to a table. There can be multiple entries of an email address for various different dates. For example, if I have the data set below. I would be looking to get the…
harold
  • 161
  • 1
  • 1
  • 3
15
votes
3 answers

How to efficiently compute a rolling unique count in a pandas time series?

I have a time series of people visiting a building. Each person has a unique ID. For every record in the time series, I want to know the number of unique people visiting the building in the last 365 days (i.e. a rolling unique count with a window of…
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
13
votes
2 answers

Pandas rolling apply with missing data

I want to do a rolling computation on missing data. Sample Code: (For sake of simplicity I'm giving an example of a rolling sum but I want to do something more generic.) foo = lambda z: z[pandas.notnull(z)].sum() x = np.arange(10, dtype="float") …
Mahesh
  • 131
  • 1
  • 5
11
votes
3 answers

Pandas rolling apply function to entire window dataframe

I want to apply a function to a rolling window. All the answers I saw here are focused on applying to a single row / column, but I would like to apply my function to the entire window. Here is a simplified example: import pandas as pd data = […
Yair Daon
  • 1,043
  • 2
  • 15
  • 27
11
votes
3 answers

Filtering out outliers in Pandas dataframe with rolling median

I am trying to filter out some outliers from a scatter plot of GPS elevation displacements with dates I'm trying to use df.rolling to compute a median and standard deviation for each window and then remove the point if it is greater than 3 standard…
p0ps1c1e
  • 176
  • 2
  • 2
  • 14
10
votes
4 answers

rolling regression by group in the tidyverse?

There are many questions about rolling regression in R, but here I am specifically looking for something that uses dplyr, broom and (if needed) purrr. This is what makes this question different. I want to be tidyverse consistent. Is is possible to…
ℕʘʘḆḽḘ
  • 18,566
  • 34
  • 128
  • 235
9
votes
1 answer

How to tackle inconsistent results while using pandas rolling correlation?

Let me preface this by saying, in order to reproduce the problem I need a large data, and that is part of the problem, that I can't predict when the peculiarity is going to pop up. Anyway, the data is too large (~13k rows, 2 cols) to be pasted in…
Sayandip Dutta
  • 15,602
  • 4
  • 23
  • 52
1
2 3
70 71