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

Fixed float NaN error #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tomszekeres
Copy link

Fixed "cannot convert float NaN to integer" error for 'week' and 'rank' in billboard.csv

Fixed "cannot convert float NaN to integer" error for 'week' and 'rank' in billboard.csv
@sprestridge
Copy link

sprestridge commented Mar 21, 2019

#1
I noticed that error as well but this fix did not work for me. If I read the fix correctly it was the addition of two lines of code to the #formatting section of the Billboard 100 example. The two lines were:

df = df[~df['week'].isnull()]

df = df[~df['rank'].isnull()]

Still getting the NaN error:

ValueError: cannot convert float NaN to integer

I believe the a correct fix is the following:

df['week'] = df['week'].str.extract('(\d+)', expand=False).astype(np.float)

verse the line currently ending as astype(int)

@RoboKiteCat
Copy link

@sprestridge thanks that helped me. I also noted that I needed to use the same approach to the next line:

df["rank"] = df["rank"].astype(np.float)

were it was previously df["rank"] = df["rank"].astype(int)

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

Successfully merging this pull request may close these issues.

3 participants