pandas 中分组值的堆叠直方图 [英] Stacked histogram of grouped values in Pandas
本文介绍了 pandas 中分组值的堆叠直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用以下代码创建堆叠的分组直方图:
titanic.groupby('Survived').Age.hist(stacked = True)
但是我得到的直方图没有堆积的条形图.
如何在不直接使用matplotlib或遍历组的情况下堆叠直方图的条形图?
使用的数据集:
i am trying to create a stacked histogram of grouped values using this code:
titanic.groupby('Survived').Age.hist(stacked=True)
But I am getting this histogram without stacked bars.
How can i get the histogram's bar stacked without having to use matplotlib directly or iterating over groups?
Dataset used: https://www.udacity.com/api/nodes/5454512672/supplemental_media/titanic-datacsv/download
解决方案
Improve the answer, the best way could be:
titanic.pivot(columns='Survived').Age.plot(kind = 'hist', stacked=True)
这篇关于 pandas 中分组值的堆叠直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文