模块 '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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 06:22:06  来源:igfitidea点击:

module 'pandas' has no attribute 'scatter_matrix'

python-3.xpandas

提问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 pandasand conda update matplotlibin 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_matrixor pandas.scatter_matrixyou 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_matrixdirectly worked like charm.

scatter_matrix直接调用就像魅力一样工作。