I have a small dataframe (df):
unique a b c d
0 None None None None
1 None None None None
2 None 0132 None None
3 None None None 0231
4 None None None None
5 None None 0143 None
6 0121 None None None
7 None None None 0432
I need to replace all values with NaN. I tried to apply df.fillna(np.NAN)
, but it does not change the value in cells, where there is a number.
How do I make all the values have been replaced?
Dataframe should look like this:
unique a b c d
0 NaN NaN NaN NaN
1 NaN NaN NaN NaN
2 NaN NaN NaN NaN
3 NaN NaN NaN NaN
4 NaN NaN NaN NaN
5 NaN NaN NaN NaN
6 NaN NaN NaN NaN
7 NaN NaN NaN NaN
Use loc
to assign np.nan
df.loc[:] = np.nan
iloc
also works
df.iloc[:] = np.nan
Just to add to the pool, this also works:
df[:] = np.nan
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With