'Error in tring to print a dataframe /np array as plt

Iam trying to print some dataframe in a matplotlib pcolor:

import pandas as pd
df = pd.read_excel("/content/aluminum.xlsx")
data=df.to_numpy(na_value=0)

data=data[1:10001,1:17]

fig = plt.figure(figsize=(3, 4))
plt.pcolor(data, cmap='seismic')
#plt.pcolor(data, cmap='seismic')

The Following error occurs:

<matplotlib.colorbar.Colorbar at 0x7f1193632290>

Error in callback <function install_repl_displayhook.<locals>.post_execute at 0x7f12a1e70320> (for post_execute):

---------------------------------------------------------------------------

TypeError                                 Traceback (most recent call last)

/usr/local/lib/python3.7/dist-packages/matplotlib/pyplot.py in post_execute()
    107             def post_execute():
    108                 if matplotlib.is_interactive():
--> 109                     draw_all()
    110 
    111             # IPython >= 2

15 frames

/usr/local/lib/python3.7/dist-packages/matplotlib/colors.py in __call__(self, X, alpha, bytes)
    559         if np.ma.is_masked(X):
    560             mask_bad = X.mask
--> 561         elif np.any(np.isnan(X)):
    562             # mask nan's
    563             mask_bad = np.isnan(X)

TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe'

I have tried to read it as a numpy array but this did not fixed it can sb help ?



Solution 1:[1]

So just in case someone else has the same problem as me. I did knot know the content of the Excel file exactly and as others pointed out: there was a string inside the File. data=df.to_numpy(dtype=float,na_value=0) produced the Error: ValueError: could not convert string to float: 'Note: ' which basically says there is a string Note: somewhere in the File. For me the Error was unclear. Thanks @MadPhysicist for the hint

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 efeder