Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dvcchamhocvcl opened this issue Mar 24, 2024 · 4 comments
Open

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

dvcchamhocvcl opened this issue Mar 24, 2024 · 4 comments

Comments

@dvcchamhocvcl
Copy link

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: '--'`

@okayy84
Copy link

okayy84 commented Apr 3, 2024

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

I find nothing on google it's insane

@okayy84
Copy link

okayy84 commented Apr 3, 2024

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.

@WillMc93
Copy link

WillMc93 commented May 14, 2024

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.

@WillMc93
Copy link

I changed my mind and made a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants