Home > Software design >  pd.read_csv causes pyplot fail to render
pd.read_csv causes pyplot fail to render

Time:01-03

I'm new to Python.

For some reason when imported data from any .csv file,

import pandas as pd
import matplotlib.pyplot as plt

dataFrame = pd.read_csv('csv1.csv')

plt.hist([2,3,4])
plt.show()

csv1.csv (actually any legit csv will be good here)

"Group A","Group B"
3,2
4,1
0,1

pyplot fail to render:

(...)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/matplotlib/ticker.py", line 2120, in tick_values
    vmin, vmax = mtransforms.nonsingular(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/matplotlib/transforms.py", line 2880, in nonsingular
    if maxabsvalue < (1e6 / tiny) * np.finfo(float).tiny:
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/getlimits.py", line 462, in __new__
    dtype = numeric.dtype(type(dtype))
TypeError: 'NoneType' object is not callable

screenshot of the empty figure

But, removing the

dataFrame = pd.read_csv('csv1.csv')

and everything is good to go. plt.scatter() also fails to render, not just hist().

I do not to understand why pyplot behaves that way.

Are pandas and matplotlib somehow not compatible?

CodePudding user response:

Okay something is probably wrong with your csv file. I ran the exact same code by recreating your csv and it produced a matplotlib graph. Please check that you're storing the csv file in the correct location (with the correct PATH relative name).

Right click on the csv file inside your code editor and it should provide an option: copy relative path. Else, open it in file explorer and copy the full path.

  • Related