Questions tagged [rolling-sum]

75 questions
0
votes
0 answers

Do multiple rolling sum using python

I need to do a rolling sum of a columns of a dataframe, verify if the sum of the rolling (2 to 5 lines) is = 0 and take all the lines from the rolling to flag them as "canceled". I tried this : df_sorted = df.sort_values('No Piece FI') df_sorted['No…
Teddy
  • 143
  • 8
0
votes
1 answer

How can I get the cumulative sum in R for X number of rows and it restarts from a specific row lets say I want to restart it from the 2nd row

I have a df like this a b 1 3 2 3 3 3 4 3 1 3 2 3 3 3 4 3 I want the solution like this. I want the moving sum of column 'a' for the 3 intersections which is the value from column b. Values of column b can change. Result a b …
0
votes
1 answer

Excel (or) Power BI, Rolling Sum

Is there any way in Excel Pivot or Power BI to do the rolling sum of the given data (let say monthly)? Let say I have a list of cases, each row represent case count and amount. The project start date and end date varied as follows. For, simplicity,…
LuZ
  • 15
  • 4
0
votes
2 answers

How can I compute a rolling sum using groupby in pandas?

I'm working on a fun side project and would like to compute a moving sum for number of wins for NBA teams over 2 year periods. Consider the sample pandas dataframe below, pd.DataFrame({'Team':['Hawks','Hawks','Hawks','Hawks','Hawks'],…
Evan
  • 373
  • 2
  • 3
  • 15
0
votes
1 answer

Group by rolling 30 minute timeinterval using python

I am quite stuck. I have a set of data looking like this: I have a date and 0 is the number of baggage for that specific time interval. I would like to create a 30 minute forward looking rolling time window, and for each time period I need the…
0
votes
1 answer

How to do rolling sum with conditional window criteria on different index levels in Python

I want to do a rolling sum based on different levels of the index but am struggling to make it a reality. Instead of explaining the problem am giving below the demo input and desired output along with the kind of insights am looking for. So I have…
imhaka
  • 37
  • 11
0
votes
1 answer

How to efficiently compute rolling sum over multiple dates, grouping by id?

Given a table containing 1 line per day dt per product_id and the turnover generated this day, how to compute efficiently a column turnover_7day containing the turnover generated by this product over the last 7 days? I found a simple query working…
politinsa
  • 3,480
  • 1
  • 11
  • 36
0
votes
1 answer

How to calculate a moving sum in python of dates if every date doesn't exist in the data?

I'm trying to calculate a moving sum in Python based off days, however I don't have every date listed in my data frame. In the example below the cum sum should account for the fact that the 2021-01-03 date is missing from the data frame import…
mf17
  • 91
  • 6
0
votes
2 answers

Sum based on condition of Rolling sum

I want to get the sum of the numbers but first checking the rolling sum for two consecutive values. In another context, I have precipitation data and if more than 3 inches of rainfall occurred over two days I want 3 inches to be added in the final…
lsangha
  • 39
  • 4
0
votes
2 answers

Rolling Sum Dplyr

If I have a dataframe and I want to use rolling sum to sum the previous n rows and the next n rows, what is the best way to do this? I'm aware of the roll_sum, but I can't find a way to use it to fit my use case. For example let's say I have the a…
ben890
  • 1,097
  • 5
  • 25
  • 56
0
votes
2 answers

How do I calculate a rolling sum with variable levels of depletion in R?

I'm trying to use R to measure how many days supply of a prescription an individual already has on-hand when they make a refill, taking into account all previous prescriptions. For example, if I had this table... member rx_id fill_date to_date…
T. Shiftlet
  • 158
  • 13
0
votes
1 answer

Pandas rolling with unsorted time series

I have a CSV with 1M records. Each record is a unique site/product/date. I am trying to use the .rolling to get a moving average for each site/product across a number of dates. However, the dates are not sorted in chronological order. My question is…
0
votes
1 answer

Pyspark pendant of Pandas' Rolling given time interval

Is there an pendant for this Pandas functionality in Pyspark? pandasDataFrame.rolling('2s', min_periods=1).sum() where the columns in question have timestamps like this 2013-01-01 09:00:00 0.0 2013-01-01 09:00:02 1.0 2013-01-01 09:00:05 …
gilgamash
  • 862
  • 10
  • 31
0
votes
3 answers

Rolling sum over an array in Python

I am given an array X and I am asked to return another array Y where y[t] = x[t] + x[t-1] and y[0] = 0 without using a for loop in Python. What I can think of is using rolling sum but I am not sure if this is the fastest way since I need to convert…
0
votes
2 answers

python/pandas rolling sum with time-varying windows

I have an array arr = [1,2,3, ..., N] and a list of windows (of length N) windows = [2,2,1, ...] Is it possible to do a rolling sum computation on arr with the time varying windows stored in windows? For example at t=3, you have arr=[1,2,3] and…
Michael
  • 7,087
  • 21
  • 52
  • 81