为什么 Pandas DataFrame.hist() 不起作用?

问题描述 投票:0回答:2

我遵循 Google 的机器学习课程。

我在这部分 – pandas

但是在我的 Mac 上,当我想使用此命令生成图表时:

california_housing_dataframe.hist('housing_median_age')

不起作用。

出现 Python 图标,但屏幕上未显示任何内容。

我在 matplotlibrc 中看到了一些有关后端参数的提示,但我的等于 MacOSX 并且它应该可以工作。

python pandas matplotlib
2个回答
27
投票

您需要致电

plt.show()
。这对我有用:

import matplotlib.pyplot as plt
california_housing_dataframe.hist('housing_median_age')
plt.show()

(详细阐述 T. Kelly 的评论)。


7
投票

我正在关注 Google ML 速成课程(根据变量名称,我认为您也在关注它)。

我也遇到同样的问题

当我打电话时

california_housing_dataframe.hist('housing_median_age')

它没有显示任何直方图。相反,它显示

array([[<matplotlib.axes._subplots.AxesSubplot object at 0x12bb814e0>]],
  dtype=object)

要显示直方图,请在导入中添加此行:

%matplotlib inline

它应该显示直方图。

© www.soinside.com 2019 - 2024. All rights reserved.