tidy-data-python
tidy-data-python copied to clipboard
Fixed float NaN error
Fixed "cannot convert float NaN to integer" error for 'week' and 'rank' in billboard.csv
#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 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)