I'm trying to set up a 5-day (adjustable) running mean for ratings I made for various dates with a Python Pandas DataFrame.
I can easily get the average mean by day using the following code
import pandas as pd
import datetime as dt
RTC = pd.read_csv(...loads file, has 'Date' and 'Rating' columns...)
daterange = RTC['Date'].max() - RTC['Date'].min()
days_means = []
for day_offset in range(daterange.days+1):
filldate = (RTC['Date'].min() + dt.timedelta).strftime('%Y-%m-%d')
days_means.append(RTC[RTC['Date']==filldate]['Rating'].mean())
I'm thinking that the most natural way to extend this would be to make filldate a list (or a series?) and then have a new mask like
RTC['Date'] in filldate
But if I do this I get an error that states
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
I'd guess somewhere I'd want to put an any-statement somewhere in this, but I cannot get this working.
Does anyone have advice on how to make this work properly?
Thanks!
EDIT: For reference, here's what my data would look like
Date Rating OtherColumns...
1-1-2014 5 ...
1-2-2014 6
1-2-2014 7
1-3-2014 8
1-3-2014 2
1-4-2014 3
1-6-2014 6
...
So the 5-day mean for 1-3-2014 would be (5+6+7+8+2+3)/6. Note that there are two entries for 1-2-2014 and 1-3-2014 nothing for 1-5-2014.