Questions tagged [rolling-average]

104 questions
1
vote
2 answers

Rolling mean returns over DataFrame

I want to add columns to the following Dataframe for each stock of 5 year (60 month) rolling returns. The following code is used to obtain the financial data over the period 1995 to 2010. quandl.ApiConfig.api_key = 'Enter Key' stocks = ['MSFT',…
oceanbeach96
  • 604
  • 9
  • 19
1
vote
1 answer

Python - Attempting to calculate the average time of events prior to time t

Here is a sample dataset: ID Date 1 2/3/18 1 2/7/18 1 2/14/18 1 2/16/18 Here is what the final feature will look like: ID Date Running_Mean 1 2/3/18 0 1 2/7/18 4 1 2/14/18 5.5 1 2/16/18 4.33 This is a rolling window…
madsthaks
  • 2,091
  • 6
  • 25
  • 46
1
vote
0 answers

Mysql 8.0 - Calculating Moving Average

Currently, I'm working on a database on Amazons rds platform, and i'm connecting through mysql server. At some point, I need to perform a rolling average of the form: SELECT id, x_axis,time, AVG(x_axis) OVER (ORDER BY time ROWS BETWEEN 8 PRECEDING…
1
vote
2 answers

Windowed Average, accounting for gaps

I need to calculate an average over the preceding 4 weeks... SELECT *, AVG(val) OVER (PARTITION BY some_identifier, day_of_week_column ORDER BY date_column ROW BETWEEN 4 PRECEDING AND 1 PRECEDING …
MatBailie
  • 83,401
  • 18
  • 103
  • 137
1
vote
1 answer

Speed up finding the average of top 5 numbers from a rolling window in python

I would like to create a column of the average of the 5 highest values from a rolling window of 30. Using a for loop is very slow with a large DataFrame. I tried using rolling() with nlargest(), but it wouldn't work. Any suggestions for speeding…
slard
  • 61
  • 1
  • 8
1
vote
1 answer

Mean between n and n+1 row in pandas groupby object?

I have a groupby object: col1 col2 x y z 0 A D1 0.269002 0.131740 0.401020 1 B D1 0.201159 0.072912 0.775171 2 D D1 0.745292 0.725807 0.106000 3 F D1 0.270844 0.214708 0.935534 4 C D1 …
1
vote
1 answer

Python Pandas rolling mean with window value in another column

I am using pandas.DataFrame.rolling to calculate rolling means for a stock index close price series. I can do this in Excel. How can I do the same thing in Pandas? Thanks! Below is my Excel formula to calculate the moving average and the window…
Tim
  • 21
  • 3
1
vote
1 answer

Moving average in a pandas dataframe on valid values (non empty rows)

I have a df like this: a001 a002 a003 a004 a005 time_axis 2017-02-07 1 NaN NaN NaN …
Joe
  • 12,057
  • 5
  • 39
  • 55
1
vote
1 answer

Python Pandas: Custom rolling window calculation

I'm Looking to take the most recent value in a rolling window and divide it by the mean of all numbers in said window. What I tried: df.a.rolling(window=7).mean()/df.a[-1] This doesn't work because df.a[-1] is always the most recent of the…
Tony
  • 13
  • 1
  • 3
0
votes
0 answers

Power BI weekly rolling average using Measure

In Power BI, I have 4 columns - date year, week no, and the respective week's sales. date Year Week No. Sales Jan-1-2022 2022 1 100 Jan-9-2022 2022 2 200 Jan-17-2023 2023 3 …
shejomamu
  • 141
  • 2
  • 13
0
votes
1 answer

Rolling average only when specific percentage of null values

I need to get the rolling average of a value on the 8 days before to the considered record. However I want it only calculated when I have at least 6 non-null values out of the 8 recorded (8 days). In other terms calculate the rolling average on 8…
0
votes
1 answer

Rolling Average of a Measure

I'm trying to find a 30-day rolling average of a measure [STORY COMPLETED] The measure is calculated as: STORY COMPLETED = CALCULATE(COUNT(SprintReportIssues[SPRINT_REPORT_STATUS]), SprintReportIssues[SPRINT_REPORT_STATUS] =…
0
votes
2 answers

Rolling average - ValueError: Columns must be same length as key

I am trying to calculate a moving average (3 years) but I get a different size object. counts = dfen.groupby(['From date', 'Policy category 1']).size().reset_index(name='counts') t = counts['counts'] counts['t_average'] = t.rolling(2).mean() I…
0
votes
0 answers

Rolling average in SQL using window function over DATETIME range

I'm trying to compute a rolling average using SQL and I was able to compute said average using the OVER and ROWS BETWEEN commands. I obtained a rolling average using the rows between the preceding 1 and following 1 rows, code seen below along with…
theneil
  • 488
  • 1
  • 4
  • 14
0
votes
0 answers

X has 3 features, but RandomForestClassifier is expecting 23 features as input

I want to determine the result of an esports game using python, but it doesn't work when i add more data to it, and i don't know why This is the code i use to predict the outcome of a game: import pandas as pd from sklearn.ensemble import…