import numpy as np prev_rank_before = f500["previous_rank"].value_counts(dropna=False).head() f500.loc[f500["previous_rank"] == 0, "previous_rank"] = np.nan prev_rank_after = f500["previous_rank"].value_counts(dropna=False).head()
I have two questions about this assignment:
- Why should you replace a 0 value with a Nan?
When I compare the output from the object:
.head()method with the
.head()method. All the values are the same and occures once. (expect the 0 value). so I don’t really see the added value of replacing 0 with a nan value.
- The explanation of this task states the following: ’ Just like in NumPy,
np.nanis used in pandas to represent values that can’t be represented numerically, most commonly missing values.’
why do we import numpy into the command when pandas also has a nan value? Or do I misunderstand something?
Looking forward to your response,