Skip to content

Fixed float NaN error#1

Open
tomszekeres wants to merge 1 commit intonickhould:masterfrom
tomszekeres:master
Open

Fixed float NaN error#1
tomszekeres wants to merge 1 commit intonickhould:masterfrom
tomszekeres:master

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