python - 无法在 Python 3.7 Notebook 中绘制简单直方图
问题描述
下面是我在尝试从 DF“代码”和列(“年龄”)做直方图时收到的错误代码
code['Age'].plt.hist()
1
code['Age'].plt.hist()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-44-2117f9d17105> in <module>
----> 1 code['Age'].plt.hist()
~\Anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
5177 if self._info_axis._can_hold_identifiers_and_holds_name(name):
5178 return self[name]
-> 5179 return object.__getattribute__(self, name)
5180
5181 def __setattr__(self, name, value):
AttributeError: 'Series' object has no attribute 'plt'
解决方案
直接从 matplotlib 使用 hist 函数:
import matplotlib.pyplot as plt
plt.hist(code['Age'])
plt.show()
这应该有效。你也可以这样做:
import matplotlib.pyplot as plt
code['Age'].hist()
plt.show()
推荐阅读
- elementor - Elementor + W3C 验证器:“此时元素 div 上不允许属性 alt”适用于所有照片库项目
- typescript - 如果未提供位置,则在报告错误时必须提供节点。运行 ESLint 7.11.0 时出现 no-unused-vars 错误
- c# - 使用具有存储库和工作单元模式的实体框架更新一对多关系中的子级
- html - 了解视口元标记
- r - 创建基于按 ID 分组的另一列的值重新启动的序列变量
- python - 奇偶排序:在 CUDA 中使用多个块时结果不正确
- javascript - JavaScript:用 JS/HTML 选项卡替换 HTML 元素
- javascript - 我如何从这个 vue.js 对象创建购物车
- python - 引用函数python之外的变量
- python - 不确定此代码如何获取树直径