Questions tagged [pandas-rolling]

questions related to the rolling method of pandas DataFrame and pandas Series objects

rolling method provides rolling window calculations.

Read more:

23 questions
0
votes
1 answer

How to lookup the previous occurrence of a row's ID in another column, and get that previous occurrence row's value?

I have a large pandas dataframe of ~2million rows. Columns A and B are both ID columns, where ID==1 in Column A is the same ID entity as ID==1 in column B. Column C is the target value column. Is there an efficient way, using pandas' native…
Mark
  • 15
  • 4
0
votes
1 answer

How to apply a rolling window mean with group by filter in Pandas

I have the following data frame: product_id year sales freq 1 2023 100 2 1 2022 200 3 2 2023 10 2 3 2022 600 3 I want to add another column that calculates and adds mean values to the data frame based on the following formula. if…
Parth
  • 35
  • 8
0
votes
1 answer

Speed up groupby rolling apply utilising multiple columns

I'm trying to create a Brier Score for a grouped rolling window. As the function that calculates the Brier Score utilises multiple columns in the grouped rolling window I've had to use the answer here as the basis for a rather hacky solution: import…
Jossy
  • 589
  • 2
  • 12
  • 36
0
votes
1 answer

How to get correlation from fixed series and rolling dataframe

Can someone help me? I want to run correlation with fixed Series in df and rolling DataFrame in df1. Desired result should be all 1 from index 1 to 6 but I got NaN. df = pd.Series([2,3,4]) df1 = pd.DataFrame({'A':[1,2,3,4,5,6,7], …
stvlam22
  • 63
  • 7
0
votes
1 answer

Pandas rolling function bug?

I have the following few samples of data: close date 2018-11-13 192.23 2018-11-12 194.17 2018-11-09 204.47 2018-11-08 208.49 2018-11-07 209.95 2018-11-06 203.77 2018-11-05 201.59 2018-11-02 207.48 2018-11-01 222.22 2018-10-31 …
Ivan
  • 7,448
  • 14
  • 69
  • 134
0
votes
0 answers

Moving average with adaptive window size

I have a DataFrame df with two columns x and y which I would like to plot as a line plot as follows: import matplotlib.pyplot as plt import seaborn as sns fig = plt.figure(figsize=(9, 7)) ax = plt.subplot(111) df = df.groupby(x,…
machinery
  • 5,972
  • 12
  • 67
  • 118
0
votes
0 answers

Applying rolling function return no value pandas

I have a data frame temps that looks like this And I am trying to apply a shift of 1 and then a rolling function with window 2 and finally taking the mean of the rolling data frame, see below code for reference, shifted = temps.shift(1) window =…
NJ1
  • 67
  • 1
  • 8
0
votes
1 answer

Workaround for pct_change not working with .rolling() in Pandas?

I have a dataframe that is over 2mm rows. It has the adjusted closing prices for all of the stocks in the S&P 500 over the past 20 years (so, a mixture of companies/tickers). The bottom section is a snapshot of my dataframe. I will be putting…
Jim
  • 1
  • 2
1
2