【问题标题】:Pandas DataFrame.hist() doesn't workPandas DataFrame.hist() 不起作用
【发布时间】:2019-01-02 06:56:56
【问题描述】:

我关注关于机器学习的谷歌课程。我在这部分:pandas

但在我的 Mac 上,当我想用​​这个命令生成图表时:

california_housing_dataframe.hist('housing_median_age')

它不起作用。 python 图标出现,但屏幕上没有显示任何内容。

我在 matplotlibrc 中看到了一些有关 backend 参数的提示,但我的等于 MacOSX,它应该可以工作吗?

感谢您的帮助

【问题讨论】:

  • 你的问题有点不清楚。您能发布您遇到的错误类型吗?
  • 我没有任何错误。当图表尝试显示时,python 图标出现。但没有出现任何窗口。
  • 你试过调用matplotlib的.show()方法吗?参考this question

标签: python pandas matplotlib


【解决方案1】:

我正在关注 Google ML Crash Course(我认为您也根据变量名称关注它)。

我也遇到了同样的问题。

当我打电话时

california_housing_dataframe.hist('housing_median_age')

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

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

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

%matplotlib inline

它应该显示直方图。

【讨论】:

    【解决方案2】:

    详细说明 T. Kelly 的评论:

    您需要调用 plt.show()。这对我有用:

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

    【讨论】:

      猜你喜欢
      • 2020-07-21
      • 1970-01-01
      • 2018-02-21
      • 2017-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-14
      • 2022-01-19
      相关资源
      最近更新 更多