Python2.7 : How to create bar graph using index and column information?

标签 python python-2.7 pandas data-visualization seaborn

我刚刚开始学习用于数据科学的 Python 2.7,遇到了一个困难,我在谷歌搜索后无法解决......如果你能帮助我如何创建条形图,我将不胜感激。

所以我有一个这样的数据框。 dataframe I have 我使用数据透视表从原始数据创建了这个数据框,将热门事件分配为索引和列中的国家/地区。里面的数据是每个国家流行事件的总票数。 由此我想根据每个国家/地区制作条形图。它可能看起来像这样。 this is a graph I want

如果有人能给我一些制作这种图表的提示,我将不胜感激?我不知道如何分配 y 轴上的索引和 x 轴上的频率。

谢谢!

最佳答案

我想你需要DataFrame.plot.barh :

import matplotlib.pyplot as plt

df.plot.barh()
#pandas version bellow 0.17.0
#df.plot(kind='barh')
plt.show()

graph

关于Python2.7 : How to create bar graph using index and column information?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38405568/

相关文章:

python-2.7 - 如何使用 GdkPixbuf 截取屏幕截图?

python - 使用Lambda函数进行分组和聚合

python - 按预定义列连接/合并数据框列表

python - 在 Reportlab 中有什么方法可以设置字体大小吗?

python - Openpyxl - 我可以使用 Openpyxl 创建水平条形图吗?

python - 在 python sqlite3 中使用保存点

python - 如何检查 TDD 中是否存在方法?

python - Django 错误 : ValueError

python-3.x - 我应该将 dict.keys() 转换为 list(dict.keys()) 以便在 Python3 中进行迭代吗? 2to3 建议将其转换为

python - 计算列中集合类型的值