python - Pandas 中分组值的堆叠直方图

标签 python pandas histogram

我正在尝试使用以下代码创建分组值的堆叠直方图:

titanic.groupby('Survived').Age.hist(stacked=True)

但我得到的直方图没有堆积条。

enter image description here

如何在不直接使用 matplotlib 或遍历组的情况下堆叠直方图的条形图?

使用的数据集:https://www.udacity.com/api/nodes/5454512672/supplemental_media/titanic-datacsv/download

最佳答案

改进答案,最好的方法是:

titanic.pivot(columns='Survived').Age.plot(kind = 'hist', stacked=True)

enter image description here

关于python - Pandas 中分组值的堆叠直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41622054/

相关文章:

python - Pandas 有没有办法过滤字符串中包含的列中的行

python - 有没有办法将 Pandas 集成到 tableau 中?

pandas - 如何使用标称值绘制 Pandas 的直方图?

python-3.x - 为 hist2d 子图添加一个颜色条并使它们相邻

python Pandas : How I can determine the distribution of my dataset?

python - 有人知道 nosetest 的 -m、-i 和 -e 是如何工作的吗?

python - 使用 beautifulsoup Python 检查 HTML 中是否存在特定类

python - 使用键创建字典,因为文件名值是内容

python - 循环数据帧时计算行的出现次数

python - Django Factoryboy 在用作默认参数值时失败