模块 'pandas' 没有属性 'scatter_matrix'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/55394041/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
module 'pandas' has no attribute 'scatter_matrix'
提问by spidermarn
I'm trying to run pd.scatter_matrix in Jupyter Notebook with my code below:
我正在尝试使用以下代码在 Jupyter Notebook 中运行 pd.scatter_matrix:
import matplotlib.pyplot as plt
import pandas as pd
from sklearn import datasets
%matplotlib inline
plt.style.use('ggplot')
# Load some data
iris = datasets.load_iris()
iris_df = pd.DataFrame(iris['data'], columns=iris['feature_names'])
iris_df['species'] = iris['target']
pd.scatter_matrix(iris_df, alpha=0.2, figsize=(10, 10))
plt.show()
but I'm getting
AttributeError: module 'pandas' has no attribute 'scatter_matrix'
.
Even after typing conda update pandas
and conda update matplotlib
in Terminal, this is still occurring.
但我得到了
AttributeError: module 'pandas' has no attribute 'scatter_matrix'
。即使在终端中输入conda update pandas
并输入后conda update matplotlib
,这种情况仍在发生。
I typed pd.__version__
to check my pandas version and it's '0.24.2'
. What could be the problem?
我输入pd.__version__
以检查我的 Pandas 版本,它是'0.24.2'
. 可能是什么问题呢?
回答by jezrael
This method is under pandas.plotting
- docsand pandas.plotting.scatter_matrix
:
这种方法是下pandas.plotting
-文档和pandas.plotting.scatter_matrix
:
from pandas.plotting import scatter_matrix
scatter_matrix(iris_df, alpha=0.2, figsize=(10, 10))
回答by Italo Gervasio
Another option is keeping only pandas import and rewriting the command scatter_matrix
, like in the example below:
另一种选择是只保留 pandas 导入并重写命令scatter_matrix
,如下例所示:
import pandas as pd
pd.plotting.scatter_matrix(iris_df, alpha=0.2, figsize=(10, 10))
回答by Hari
Using
使用
from pandas.plotting._misc import scatter_matrix
don't use pd.scatter_matrix
or pandas.scatter_matrix
you can directly call scatter_matrix
不要使用pd.scatter_matrix
或者pandas.scatter_matrix
你可以直接调用scatter_matrix
e.g.
例如
cmap = cm.get_cmap('gnuplot')
scatter = scatter_matrix(X, c = y, marker = 'o', s=40, hist_kwds={'bins':15},
figsize=(9,9), cmap = cmap)
plt.suptitle('Scatter-matrix for each input variable')
plt.savefig('fruits_scatter_matrix')
plt.show()
回答by Marcell Kovacs
I used
我用了
from pandas.plotting import scatter_matrix
and called scatter_matrix
directly worked like charm.
并scatter_matrix
直接调用就像魅力一样工作。