dataframe 根据某行的值取平均数

如下图片

img


这是一个dataframe形式
取里面所有A的均值和B C 的均值该怎么去算

import pandas as pd
ls = [[0,1],['A',5],['B',6],['C',8],['A',4],['B',4]]
df = pd.DataFrame(ls)
dfcount = df[1].groupby(df[0]).count()
dfsum = df[1].groupby(df[0]).sum()
dfsum/dfcount

img


如有用请采纳

平均值有个通用代码 mean,所以一楼的应该写成

ls = [[0,1],['A',5],['B',6],['C',8],['A',4],['B',4]]
df=pd.DataFrame(ls)
df=df.groupby(0).mean()
print(df)