Python 从两个不同的变量中求平均值

Python 从两个不同的变量中求平均值,python,pandas,Python,Pandas,我有一个 df = pd.DataFrame({"type" :["A","B","C","A","B","B"], "value": [40,25,33,22,45,62]}) 我想找出每种类型的平均值,也就是说,type=A的平均值为31 我是通过子集来做的 df_a = df.loc[df['type']=="A&quo

我有一个

df = pd.DataFrame({"type" :["A","B","C","A","B","B"], "value": [40,25,33,22,45,62]})
我想找出每种类型的平均值,也就是说,type=A的平均值为31 我是通过子集来做的

df_a = df.loc[df['type']=="A"]
df_a['value'].mean()
我想在一行中完成它,
提前感谢

一个可能的解决方案可能是:

df.gropuby('type')['value'].mean()
df.gropuby('type')['value'].mean()