I have a dataframe df
like below.
dates = pd.date_range('2000-01-01', '2001-01-01')
df1 = pd.DataFrame({'date':dates, 'value':np.random.normal(size = len(dates)), 'market':'GOLD'})
df2 = pd.DataFrame({'date':dates, 'value':np.random.normal(size = len(dates)), 'market':'SILVER'})
df = pd.concat([df1, df2])
df = df.sort('date')
date market value
0 2000-01-01 GOLD -1.361360
0 2000-01-01 SILVER 0.255830
1 2000-01-02 SILVER 0.196953
1 2000-01-02 GOLD 1.422454
2 2000-01-03 GOLD -0.827672
...
I want to add another column as the 10d moving average of value, for each market.
Is there a simple df.groupby('market').???
that can achieve this? Or do I have to pivot the table to wide form, smooth each column, then melt back?