viv*_*vek 1 matplotlib python-3.x jupyter-notebook
我无法在 Jupyter 笔记本中绘制直方图。这是下面的代码和响应它的错误消息。
import pandas as pd
import numpy as np
from sklearn.datasets import load_boston
import matplotlib.pyplot as plt
housing_data = load_boston()
%matplotlib inline
housing_data.hist(bins = 50, figsize = (20, 15))
plt.show()
KeyError Traceback (most recent call last)
/anaconda3/lib/python3.6/site-packages/sklearn/utils/__init__.py in __getattr__(self, key)
60 try:
---> 61 return self[key]
62 except KeyError:
KeyError: 'hist'
During handling of the above exception, another exception occurred:
AttributeError Traceback (most recent call last)
<ipython-input-17-570a88b85d5d> in <module>()
----> 1 housing_data.hist(bins = 50, figsize = (20, 15))
2 plt.show();
/anaconda3/lib/python3.6/site-packages/sklearn/utils/__init__.py in __getattr__(self, key)
61 return self[key]
62 except KeyError:
Run Code Online (Sandbox Code Playgroud)
---> 63 raise AttributeError(key) 64 65 def setstate (self, state):
AttributeError: hist
Run Code Online (Sandbox Code Playgroud)
我是新手,请帮助我。
import pandas as pd
import numpy as np
from sklearn.datasets import load_boston
import matplotlib.pyplot as plt
housing_data = load_boston()
%matplotlib inline
pd.DataFrame(housing_data['data']).hist(bins = 50, figsize = (20, 15))
Run Code Online (Sandbox Code Playgroud)
您必须访问包含数据的 numpy 数组字典,然后将其转换为 Pandas 数据框才能使用 .hist