tidy-data-python icon indicating copy to clipboard operation
tidy-data-python copied to clipboard

Fixed float NaN error

Open tomszekeres opened this issue 6 years ago • 2 comments

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

tomszekeres avatar Feb 25 '19 21:02 tomszekeres

#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)

sprestridge avatar Mar 21 '19 20:03 sprestridge

@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)

RoboKiteCat avatar Feb 01 '21 16:02 RoboKiteCat