在Pandas数据框中通过分组行值来计算平均值。

huangapple go评论69阅读模式
英文:

Finding average by grouping row values pandas dataframe

问题

我在Python中编写了这行代码,但没有得到期望的输出。有人可以帮我吗?

我尝试了许多分组方法,但我从未得到期望的输出。

英文:
data=df.groupby('Term')['Subject'].apply(tuple)

I wrote this line in python but I didn't achieved desired output. Can anyone help me out.

I tried many grouping methods but I never came up with the output.

答案1

得分: 1

如果你正在查看按Term分组的Subject列的平均值,你实际上相当接近了:

df.groupby('Term')['Subject'].mean()
英文:

If you are looking at the average of the Subject column grouped by Term, you were actually quite close:

df.groupby('Term')['Subject'].mean()

huangapple
  • 本文由 发表于 2023年1月9日 15:56:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/75054446.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定