学习技能、解决问题,我们的目标是 Error: no error
dg = df.groupby((df.index//5)*5).mean()['matches-ratio']
dg.plot()
这可以按性别对我的数据进行分组(一列):
dg = df.groupby(['gender'])['matches-ratio']
dg.plot()
但我似乎无法按性别和5年年龄段进行分组.我已经尝试过类似dg = df.groupby([‘gender’,(df.index // 5)* 5]).mean()[‘matches-ratio’]的方法,但这给出了奇怪的结果,其中日期是按性别(???)和5年组进行分组,因此x轴标记为“性别,日期”.链接它们,如下所示:
dg = df.groupby(['gender'])['matches-ratio']
dg = dg.groupby((df.index//5)*5).mean()
dg.plot()
给定AttributeError:无法访问“ SeriesGroupBy”对象的可调用属性“ groupby”,请尝试使用“ apply”方法.如何在不同的轴上分组两次? (日期= x轴,“匹配比率” = y轴)
(df.groupby(['gender', (df.index//5)*5])
.mean()['matched-ratio']
.unstack()
.plot())
这将为每个性别创建一个单独的行.
相关问答