pandas groupby: an overall/total row?

*爱你&永不变心* 提交于 2021-02-11 14:18:44

问题


I have the following:

maths = {'floatval': 'mean'}
out = df.groupby(['pid', 'year', 'month']).agg(maths)

Which gives me a grouped mean of floatval per year and month, which is great, but I want an all/overall row, which has the mean val of floatval across a row just grouped by pid. Should I make a second data frame and combine, or is there a more efficient way?

来源:https://stackoverflow.com/questions/51712739/pandas-groupby-an-overall-total-row

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!