ResidentMario/missingno

Heatmap ValueError:could not convert string to float: '--'

Opened this issue · 4 comments

Im trying missingno.heatmap on the NYPD Motor Vehicle Collisions Dataset.
import pandas
import missingno
df = pandas.read_csv('Motor_Vehicle_Collisions_-_Crashes_20240322.csv')
missingno.heatmap(df)
Then this error occured
`ValueError Traceback (most recent call last)
Cell In[3], line 1
----> 1 missingno.heatmap(df)

File c:\Users\Admin\anaconda3\envs\jup2\lib\site-packages\missingno\missingno.py:398, in heatmap(df, filter, n, p, sort, figsize, fontsize, labels, label_rotation, cmap, vmin, vmax, cbar, ax)
395 ax0.patch.set_visible(False)
397 for text in ax0.texts:
--> 398 t = float(text.get_text())
399 if 0.95 <= t < 1:
400 text.set_text('<1')

ValueError: could not convert string to float: '--'`

Hello, I've the same issue... Please tell me that you find a solution ?

I find nothing on google it's insane

In the original missingno.py i deleted the insade loop (line 350 and i just replace by

for text in ax0.texts:
t = text.get_text()
print(t)

and the result is in the picture result.png :

Capture d’écran de 2024-04-03 13-24-29

It's seem that there's a problem in this library ! (i use the missingno 0.4.2 i can't use the latest version cause it's a pc for my job.

Okay, so the simplest way I found around this was to modify the file in my local environment to just check for the string '--' in that bit of the code.

For the contributers to the package, all I did was replace the for loop at line 397 of missingno.py with:

for text in ax0.texts:
    if text.get_text() != '--':
        t = float(text.get_text())
    else:
        continue
    
    if 0.95 <= t < 1:
        text.set_text('<1')
    elif -1 < t <= -0.95:
        text.set_text('>-1')
    elif t == 1:
        text.set_text('1')
    elif t == -1:
        text.set_text('-1')
    elif -0.05 < t < 0.05:
        text.set_text('')
    else:
        text.set_text(round(t, 1))

    return ax0

I don't feel I know enough about what's going on in the package to create a pull request for this change, but I don't see where the problem would arise TBH.

I changed my mind and made a pull request.