James Steele
James Steele

Reputation: 654

pandas valid null values

I am looking for the list of valid null values that pandas fillna() method will replace, e.g. 'NaN', 'NA', 'NULL', 'NaT'. I could not find it in the documentation.

Upvotes: 0

Views: 3640

Answers (1)

Prikers
Prikers

Reputation: 958

fillna method will only replace actual missing values represented as NaN or NaT or None but not as strings ('NaN' or anyother string). Before using fillna you can check what will be replaced in a column COL of your dataframe df using isnull():

df.loc[df['COL'].isnull()]

will show you the subset of your dataframe for which the column 'COL' is NaN/NaT/None.

You can replace strings to NaN using replace. Say you have strings like "NAN":

from numpy import nan
df = df.replace('NAN', nan)

refer to this post

Upvotes: 1

Related Questions