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?
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.
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”.
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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With