Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I solve " module 'pandas' has no attribute 'scatter_matrix' " error?

I'm trying to run pd.scatter_matrix() function in Jupyter Notebook with my code below:

import matplotlib.pyplot as plt import pandas as pd  # 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 executing conda update pandas and conda update matplotlib commands in Terminal, this is still occurring.

I executed pd.__version__ command to check my pandas version and it's '0.24.2'. What could be the problem?

like image 917
spidermarn Avatar asked Mar 28 '19 09:03

spidermarn


People also ask

How do I fix attribute error in pandas?

The AttributeError: module 'pandas' has no attribute 'DataFrame' occurs when you misspell DataFrame or override the pandas import. You can solve this error by ensuring your variables and python scripts are not named after pandas. Generally, do not name variables or scripts after existing Python libraries.

How do you fix pandas has no attribute DataFrame?

If you have named the script as pd.py or pandas.py then you will get module 'pandas' has no attribute 'dataframe' error. This mainly happens because the file name will shadow the Pandas module and, it can mess up the module imports. We can fix this issue by renaming the script to some other name such as “my_script.py”.


1 Answers

This method is under pandas.plotting - docs and pandas.plotting.scatter_matrix:

from pandas.plotting import scatter_matrix  scatter_matrix(iris_df, alpha=0.2, figsize=(10, 10)) 
like image 149
jezrael Avatar answered Sep 18 '22 08:09

jezrael