Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python-pandas, np.nan [duplicate]

Tags:

python

pandas

nan

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.

like image 727
Vinh Nguyen Avatar asked Dec 30 '22 22:12

Vinh Nguyen


2 Answers

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.

like image 171
Algebra8 Avatar answered Jan 06 '23 02:01

Algebra8


use np.isnan(np.nan) which gives True or

np.isnan(df.iloc[31464]['SalesPersonID']) which gives True

like image 37
Anurag Dhadse Avatar answered Jan 06 '23 02:01

Anurag Dhadse