Could you guys please help me explain the code below:
Why a nan
is not np.nan
?
import pandas as pd
import numpy as np
df.iloc[31464]['SalesPersonID']
[out]:
nan
df.iloc[31464]['SalesPersonID'] is np.nan
[out]:
False
Thank you, all.
Could you guys please help me explain the code below:
Why a nan
is not np.nan
?
import pandas as pd
import numpy as np
df.iloc[31464]['SalesPersonID']
[out]:
nan
df.iloc[31464]['SalesPersonID'] is np.nan
[out]:
False
Thank you, all.
np.nan
is a special value in numpy. Read here for more information on it.
The link above mentions the following code snippet:
>>> np.nan == np.nan # is always False! Use special numpy functions instead.
Also, type(df.iloc[31464]['SalesPersonID'])
is np.float64
.
use np.isnan(np.nan)
which gives True or
np.isnan(df.iloc[31464]['SalesPersonID'])
which gives True
© 2022 - 2024 — McMap. All rights reserved.
nan == nan
is False whilenan in [nan]
is True? – Ibnsina