Questions tagged [rolling-sum]

75 questions
3
votes
1 answer

RcppRoll Window Opening

I've been using the RcppRoll package to do rolling sums, but I'd like to find a function/option that would allow me to turn a vector like this [1 2 3 4 5] into [1 3 6 9 12] for a window of 3, for instance. Currently, I've been using roll_sum,…
dc4
  • 31
  • 1
3
votes
1 answer

Python Pandas rolling sum place value at the top of window

I would like to use the rolling method of Pandas. I need a slight adjustment, however, I would like the 'value' placed at the top of the 'window'. Currently, I am using this: self.df['new_col'] = self.df['Zone3'].rolling(4).sum() Which is producing…
dudeguy
  • 57
  • 5
3
votes
1 answer

Pandas: Rolling sum with multiple indexes (i.e. panel data)

I have a dataframe with multiple index and would like to create a rolling sum of some data, but for each id in the index. For instance, let us say I have two indexes (Firm and Year) and I have some data with name zdata. The working example is the…
Adrien
  • 461
  • 5
  • 19
2
votes
2 answers

Find longest rolling sum under/equal a threshold for each group

I am trying to find the most efficient way to identify the longest rolling sum of a vector where the value is below a specific threshold. For instance, if we had 1:10 and a threshold of 6, then 3 is our longest rolling sum. I have got the below code…
caldwellst
  • 5,719
  • 6
  • 22
2
votes
1 answer

Add n values from the both sides of a pandas data frame column values

I have a data frame like this, df col1 col2 A 1 B 3 C 2 D 5 E 6 F 8 G 10 I want to add previous and next n values of a particular value of col2 and store it into a new column, So, If n=2,…
Kallol
  • 2,089
  • 3
  • 18
  • 33
2
votes
2 answers

Cumulative sums in R with multiple conditions?

I am trying to figure out how to create a cumulative or rolling sum in R based on a few conditions. The data set in question is a few million observations of library loans, and the question is to determine how many copies of a given book/title…
2
votes
0 answers

Rolling window with offset different on Pandas DataFrame with PeriodIndex and DatetimeIndex

When creating a pandas DataFrame with a daily PeriodIndex, and doing a rolling window calculation based on an offset (e.g. '5D') the result is not as expected. I expect the rolling window to be the last 5 days, but instead the window seems to be…
ØVR
  • 21
  • 1
2
votes
1 answer

Rolling sum of the next N elements, including the current element

Good Morning, I have the following dataframe: a = [1,2,3,4,5,6] b = pd.DataFrame({'a': a}) I would like to create a column that sums the next "n" rows of column "a", including the present value of a; I tried: n = 2 b["r"] = pd.rolling_sum(b.a,…
Alessandro Ceccarelli
  • 1,775
  • 5
  • 21
  • 41
2
votes
1 answer

Rolling sum of last 12 rows for every column in a data frame in r

I have a data frame looking like this: Data frame The columns only have data every third month. For all columns, except the first one, i want a running sum for the last 12 rows in a new data frame. I have succesfully done this using a for loop with…
Rasmus
  • 43
  • 3
2
votes
2 answers

Conditional sum in rolling window

I am quite new to R, so apologies in advance if I state something wrong :) I have a dataframe consisting of 395 rows and 4973 columns, sorted by months, with number of occurrence per month (ranges from 0 to eg 25) for a lot of companies. The number…
Henky
  • 69
  • 7
2
votes
2 answers

Rolling 12 Month sum in PowerPivot

In PowerPivot Excel 2016 I write a formula for rolling 12 month sum of sales as below : Rolling Sum:=CALCULATE ( [Sales] , DATESBETWEEN ( Sales[Date], FIRSTDATE(DATEADD(Sales[Date],-365,DAY)), LASTDATE (Sales[Date] ) ) ) But it seems…
Ahmad AB
  • 45
  • 1
  • 6
2
votes
1 answer

PowerPivot Filter Function

In PowerPivot Excel 2016 I write a formula to summarize year to date sales using filter function as below: SalesYTD:=CALCULATE ( [Net Sales], FILTER ( ALL ( Sales), 'sales'[Year] = MAX ( 'Sales'[Year] ) && 'Sales'[Date] <= MAX (…
Ahmad AB
  • 45
  • 1
  • 6
1
vote
2 answers

Running, Rolling Sum in a specified window in R

I want to determine the running total of a column within a specified date…
Bea
  • 15
  • 6
1
vote
2 answers

Rolling Sum by 3 Conditions in R based on another data frame

I've got a df and i need to perform a rolling sum in another dataframe based on the values of the first df All the transactions of each company, by date & account This is the dataframe I want to build with the balance at the end of the day with…
1
vote
2 answers

Cumulative sum when value in other column is non-zero

I have a huge dataframe with multiple columns as below . I am trying to find cummulative sum of time when value in b is -1 which is preceeded by 1. I have tried cummulative sum but it's not working. I am looking for cumulative sum of values only…
anonymous13
  • 581
  • 1
  • 5
  • 17