Aggregate By Repeated Values In A Column In A Data Frame In Pandas
I have a data frame as follows: value identifier 2007-01-01 0.781611 55 2007-01-01 0.766152 56 2007-01-01 0.766152 57 2007-02-01 0.705615 5
Solution 1:
If your index is a datetime then you can access the .date
attribute, if not you can convert it using df.index = pd.to_datetime(df.index)
and then perform a groupby on the date and calc the mean:
In [214]:
df.groupby(df.index.date)['value'].mean()
Out[214]:
2007-01-01 0.771305
2007-02-01 0.256628
2008-01-01 0.670920
2008-02-01 0.098047
Name: value, dtype: float64
Post a Comment for "Aggregate By Repeated Values In A Column In A Data Frame In Pandas"