I have a df such as:
seed value
1 2
1 3
1 4
2 20
2 60
would like to get a shorter dataframe (df_short) with the average value for same seeds, such as
seed value
1 3
2 40
tried df.groupby("seed"), seems working, though I am getting a DataFrameGroupBy object, which I cannot use as a dataframe. Then from the question Convert DataFrameGroupBy object to DataFrame pandas, I tried the following:
from pandas import *
df = DataFrame({'seed' : [1 ,1, 1, 2, 2],
'value' : [2, 3, 4, 20, 60]})
df_short=df.groupby('seed').aggregate(np.mean)
print df_short #works as expected
print df_short['seed'] #error
print list(df_short.columns.values)
should give me ['seed', 'value']