python - 数据框的直方图

标签 python python-3.x pandas dataframe histogram

我有一个数据框如下: enter image description here

我试图从中绘制一个直方图,使得字母 {A,B,C,D} 位于 x 轴,y 轴显示数字。我已经尝试过以下方法:

df.plot(kind='hist')

我得到的是地址而不是绘图,即:

<matplotlib.axes._subplots.AxesSubplot at 0x11217d5f8>

我想知道如何展示情节?

最佳答案

IIUC,我认为您需要转置dataframe以获取索引['A','B','C','D']为x-轴,然后绘图。还可以使用 plt.show() 来显示直方图。最新版本的pandas将直接显示带有轴对象显示的绘图。但是,对于旧版本需要显式编写 plt.show() 代码来显示。

import matplotlib.pyplot as plt
df.T.plot(kind='hist')
plt.show()

关于python - 数据框的直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49731494/

相关文章:

python - 获取 DataFrame 列作为值列表

python - 将字符串转回日期时间 timedelta

python-3.x - 如何使用Python3从dll中查找函数名称?

python - 如何从深度差异中完全排除 "type_changes",因为我只关心值的变化?

python - 如何在 Python 2.7 中加载 Python 3 pickle *不改变它*?

Python MySQL 批量插入字符编码错误

python - 如何配置pycharm使用nose2代替nose

python - 如何重构使用 argparse 的脚本以在另一个 Python 脚本中调用?

python - 在我自己的 C 模块中使用 python 模块的 C API

python - 过滤窗隔板至少有 3 个 5 分钟间隙