python - pandas groups by column A and column B, and averages column C. How to generate a dataframe of columns A, B, and C?
怪我咯
怪我咯 2017-05-24 11:35:08
0
2
795
df = df.groupby(['A','B'])['c'].mean()

In this way, df is grouped, but how to turn df into a dataframe with columns A, B, and C?
Thanks

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
为情所困

I asked this question on stackoverflow, and some netizens gave me the answer. In fact, you only need to add one parameter. The method is as follows:

df = df.groupby(['A','B'],as_index = False)['C'].mean()
習慣沉默

At least one reassignment is needed to extract these three columns. The grouping method seems to be like yours

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template