Problems importing pandas.plotting
Asked Answered
H

4

23

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

Housebreak answered 21/5, 2017 at 22:47 Comment(1)
I reinstalled pandas package and got solved the issue!Wolfish
S
53

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
Sunnisunnite answered 21/5, 2017 at 22:49 Comment(1)
In their defense the documentation does refer to pandas.plotting.Cargile
W
11

If you get this warning:

main:1: FutureWarning: 'pandas.tools.plotting.scatter_matrix' is deprecated, import 'pandas.plotting.scatter_matrix' instead.

import pandas.plotting

or

from pandas.plotting import scatter_matrix

https://github.com/pandas-dev/pandas/pull/13579/files/fe8b918a7c7f322a6806d3b262b7b36bbd01da80#diff-52364fb643114f3349390ad6bcf24d8f

Waaf answered 13/6, 2017 at 20:52 Comment(0)
E
1

I figured out that most cases when the errors come up on the import scatter_matrix, it is because you have not restarted your jupyter notebooks for a while. Before I run the code; from pandas.tools.plotting import scatter_matrix I make sure I restart my jupyter notebook and run the code. Everything works just fine from then on.

Eisenhart answered 28/5, 2019 at 7:39 Comment(0)
E
1

Just use this in importing scatter_matrix:

import pandas.plotting
# insert your scatter_matrix code here and run
# there should be no error messages (unless a new one)

To remove the array texts, you can put a ";" at the end of the code

import pandas.plotting
scatter_matrix(df, ...); #put the semi-colon here
Evetteevey answered 12/12, 2019 at 18:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.