【发布时间】:2021-06-16 11:09:42
【问题描述】:
我知道有人问过this similar question;但是,如果可能的话,我正在寻求进一步的说明,以便更好地理解 .groupby 。 Data used
我想要这样的完全相同的结果,但使用 .groupby():
df.pivot(columns='survived').age.plot.hist()
所以我试试:
df.groupby('age')['survived'].count().plot.hist()
x 轴看起来不正确。有什么方法可以得到与 .pivot() 使用纯 .groupby() 方法相同的结果?谢谢。
【问题讨论】:
-
有点等价于
(df['survived'].groupby(pd.cut(df.age, bins=10)) .value_counts() .unstack().plot.bar(width=0.4) )。
标签: pandas pandas-groupby pivot-table histogram