【发布时间】:2019-05-25 22:19:41
【问题描述】:
我已将数据框按两列(用户和月份)分组,然后使用 mean() 来获取每个月的“分数”值的平均值。我现在想做的是按用户遍历组,并能够获得每个月的月份和平均分数,以便我可以使用 matplotlib 绘制它们。问题是,当我遍历组时,我会为每个用户重复一个月,而不是仅仅遍历第一个(用户)组。请告诉我这是怎么可能的,谢谢。
这是我目前所拥有的:
user_group = past_year.groupby(['User','month'])['Score'].mean()
for group in user_group:
#I want to be able to access all months and mean scores for the current user here
【问题讨论】:
标签: python pandas pandas-groupby