Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems importing pandas.plotting

Tags:

When I import pandas, everything is fine and working. Yet, when I try to import something from pandas.plotting im getting an error. What could be the source of this?

Here is how the output looks like:

>>> import pandas >>> from pandas.plotting import scatter_matrix Traceback (most recent call last):   File "<stdin>", line 1, in <module> ImportError: No module named plotting 

The pandas version Im using is: 0.19.2

like image 706
frmsaul Avatar asked May 21 '17 22:05

frmsaul


People also ask

Why is import pandas as PD not working?

The most frequent source of this error is that you haven't installed Pandas explicitly with pip install pandas . Alternatively, you may have different Python versions on your computer, and Pandas is not installed for the particular version you're using.

What is the difference between import pandas and import pandas as PD?

The import pandas portion of the code tells Python to bring the pandas data analysis library into your current environment. The as pd portion of the code then tells Python to give pandas the alias of pd. This allows you to use pandas functions by simply typing pd. function_name rather than pandas.

Do you have to import pandas every time?

Remember, you'll need to import pandas every time you run a script or start up a new jupyter notebook.


1 Answers

Unfortunately, it looks as though there has been some confusion around the movement of that module. The plotting module has been moved from pandas.tools.plotting to pandas.plotting. The difficulty is most likely stemming from the fact that as of version 0.19, the pandas.plotting library did not exist.

The current version is version 0.22. If you receive this error, the best practice is to update your version of pandas to the most recent version.

If, for some reason, you are unable to do this, the correct code for earlier versions of pandas would be

from pandas.tools.plotting import scatter_matrix 

The correct code for current versions of pandas would be

from pandas.plotting import scatter_matrix 
like image 129
spies006 Avatar answered Oct 15 '22 22:10

spies006