Questions tagged [rolling-sum]

75 questions
1
vote
2 answers

Getting the rolling.sum of row values with irregular time intervals

I am trying to get the rolling.sum of my time series. However, the rows have varying time intervals (see below my df_water_level_US1 dataframe): DATE TIMEREAD WATERLEVEL(M) DateAndTime 0 01/01/2016 0:00:15 0.65 01/01/2016 0:00:15 1…
kiwi_kimchi
  • 345
  • 3
  • 12
1
vote
1 answer

How to get tally (rolling sum) by group in R?

I would like to create a column called "tally" in my dataset that takes sums the count of each type and rank. type <- c("A","A","A","B","B","C") rank <- c("low", "med", "high","med", "high", "low") count <- c(9,20,31,2,4,14) df <- data.frame(type,…
KC Ray
  • 77
  • 9
1
vote
1 answer

Pandas dataframe rolling sum column with groupby

I'm trying to create a new column that gives a rolling sum of values in the Values column. The rolling sum includes 4 rows i.e. the current row and the next three rows. I want to do this for each type in the 'Type' column. However, if there are…
runraver
  • 15
  • 5
1
vote
1 answer

How can I create a new dataframe by taking the rolling COLUMN total/sum of another dataframe?

import pandas as pd df = {'a': [1,1,1], 'b': [2,2,2], 'c': [3,3,3], 'd': [4,4,4], 'e': [5,5,5], 'f': [6,6,6], 'g': [7,7,7]} df1 = pd.DataFrame(df, columns = ['a', 'b', 'c', 'd', 'e', 'f', 'g']) dg = {'h': [10,10,10], 'i': [14,14,14], 'j':…
1
vote
3 answers

Rolling Sum when date is continuous

I'm trying to find how many days people have continuously worked in SQL. I'm thinking a rolling sum might be the solution but don't know how to work it out. My sample data is | Employee | work_period | | 1 | 2019-01-01 | | 1 |…
Lambo
  • 857
  • 3
  • 14
  • 39
1
vote
1 answer

Returning rows with rolling sum reaches a desired value in SQL Server

I have a table create table emp ( id, int, salary int ) I need to return all rows having a rolling sum less than a given input X order by id. Query I have thought of is: Select * From (select id, salary, sum(salary) over (order by…
pvjhs
  • 549
  • 1
  • 9
  • 24
1
vote
1 answer

How to create a new column with values after groupby & rollingsum?

I am trying to create a new column in an existing df. The values of the new column are created by a combination of the groupby and rolling sum. How do I do this? I've tried two approaches both resulting in either NaN values or 'incompatible index of…
1
vote
1 answer

Pandas Rolling Window At Previous Step

I've used the rolling method to generate rolling sums and averages for each row in my df and this has worked. My question is, is there an argument that allows me to set the rolling window value calculated at the row previous to the row the pointer…
Odisseo
  • 747
  • 1
  • 13
  • 32
1
vote
1 answer

Excluding most recent day from rolling sum

I have a pandas dataframe, excerpt shown below, of rainfall data. 'Pcp' is a one day total, which I have then used to calculate rolling cumulative totals of rainfall for the other periods of time leading up to the day of interest (3 days up to 28…
SHV_la
  • 875
  • 1
  • 10
  • 14
1
vote
2 answers

Python Pandas rolling sum operation for subset of dataframe

This is best explained through an example. I have the following dataframe (each row can be thought of as a transaction): DATE AMOUNT 2017-01-29 10 2017-01-30 20 2017-01-31 30 2017-02-01 40 2017-02-02 50 2017-02-03 60 I would like to…
Zi Xiang
  • 21
  • 5
1
vote
1 answer

pandas:conditional rolling sum of two columns

I'd like to calculate a measure for momentum of soccer teams, in this case the points that a certain team got in its last 3 games. My data looks as follows: HomeTeam AwayTeam H_Pts A_Pts Barcelona Getafe 3 0 Levante …
Konninger
  • 87
  • 6
1
vote
1 answer

Recombine groupby rollling sum with original pandas DataFrame

I have a pandas DataFrame of the form: import pandas as pd df = pd.DataFrame({ 'a': [1,2,3,4,5,6], 'b': [0,1,0,1,0,1] }) I want to group the data by the value of 'b' and add new column 'c' which contains a rolling sum of 'a' for each…
user1684046
  • 1,739
  • 2
  • 13
  • 15
1
vote
1 answer

Conditional rolling sum

This is the data frame Date ID cost Value 15/12/2016 1 yes 200 15/10/2016 1 yes 100 15/9/2016 1 yes 55 15/04/2016 1 yes 1000 15/12/2016 2 yes 300 15/10/2016 2 yes 200 15/9/2016 2 yes 100 15/04/2016 …
Tyu1990
  • 147
  • 1
  • 1
  • 6
1
vote
2 answers

Pandas: Getting a rolling sum while grouping by a column

I have a pandas dataframe that looks like Name Date Value Sarah 11-01-2015 3 Sarah 11-02-2015 2 Sarah 11-03-2015 27 Bill 11-01-2015 42 Bill 11-02-2015 5 Bill 11-03-2015 …
John
  • 1,405
  • 2
  • 14
  • 21
0
votes
3 answers

Dynamic rolling sum in excel

How can I calculate the rolling sum of a column based on another column? Example: Input data are the first 3 columns in the below table. The result column that I am trying to get is highlighted in green. I want to get the dynamic sum of 'Daily…
VanodyaPerera
  • 137
  • 1
  • 1
  • 10