Home > Software engineering >  How can I drop nan(s)?
How can I drop nan(s)?

Time:11-26

Unique values of the column as follows:

array(['..', '0', nan, ..., '30.0378539547197', '73.3261637778593',
       '59.9402466154723'], dtype=object)

I use the following codes to drop NaNs and None.

df[df["Country Name"].isin([None]) == False]

and it still includes the NaNs.

CodePudding user response:

You can use .isna to check for nan.

df[~df["Country Name"].isna()]

CodePudding user response:

Did you try this df = df.dropna() ?

CodePudding user response:

You can probably use "dropna" method if the NaN's are in a correct format.

And if you want to do it for a particular column then, use

df["column_name"].dropna()

or

df.dropna(subset=['column_name1', 'column_name2'])

I hope this helps!!!

  • Related