Home > Back-end >  No longer able to make simply dataframe plots in python
No longer able to make simply dataframe plots in python

Time:10-02

so I am experience an odd issue with python, where all of the sudden, I am not longer able to create simple plots.

I am just trying to run this simple example from: https://www.geeksforgeeks.org/python-pandas-dataframe-plot-bar/

Where I run:

# importing matplotlib
import matplotlib.pyplot
  
# importing pandas as pd
import pandas as pd
  
# importing numpy as np
import numpy as np
  
# creating a dataframe
df = pd.DataFrame(np.random.rand(10, 10),
                  columns =['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'])
  
df

to create a dataframe. And then I try to plot via:

df.plot.bar()

and then receive this error:

TypeError: Cannot interpret '<attribute 'dtype' of 'numpy.generic' objects>' as a data type

I have been receiving this error for plots I should be able to create, and I cannot figure out why this is happening and why python cannot interpret the data. Could someone please help me understand this?

CodePudding user response:

Try to update to pandas >= 1.0.5 should solve it. Supposedly also pandas==0.25.3 works. If stuck with pandas 0.24.x, unfortunately you may not be able to use numpy 1.20.x though. In that case, use numpy < 1.20.

..or before everything, try :

pip install numpy --upgrade
pip install pandas --upgrade
pip install matplotlib --upgrade

CodePudding user response:

If you are using Conda, it may be causing a conflict. You may have to downgrade/ upgrade numpy from outside the env to match the one inside the env.

This issue on github has more information about this problem if you are using conda: https://github.com/numpy/numpy/issues/18355

  • Related