381-10 Pandas 10/14 F500 previous_rank

Receiving error on step 10/14 of pandas module , using boolean filtering and vector assignment for previous rank column in f500 data frame: here is is my code
Any guidance on this, much appreciated

import numpy as np
prev_rank_before = f500[“previous_rank”].value_counts(dropna=False).head()

#rank_null = f500[“previous_rank”] == 0
#f500.loc[rank_null, “previous_rank”] = “np.nan”

f500.loc[f500[“previous_rank”] == 0, “previous_rank”] = “np.nan”

prev_rank_after = f500[“previous_rank”].value_counts(dropna=False).head()

my actual output for f500 and prev_rank_before/after is not same as expected, see link below


Hi there. Do you have quotes around np.nan in your actual code? That’s the only problem I can see.

1 Like

Hello April

Yes np.nan is in quotes, tried resetting the code from scratch, the same error,
Values for f500 and the prev_rank_before/after is not same as expected

Did you remove the quotes from np.nan? Just trying to cover all the bases here. Putting quotes around it makes it literally put ‘np.nan’ instead of the null value that the answer is expecting.