remove nan from dataframe python code example

Example 1: remove nan from list python

cleanedList = [x for x in countries if str(x) != 'nan']

Example 2: pandas filter non nan

filtered_df = df[df['name'].notnull()]

Example 3: how to delete nan values in python

x = x[~numpy.isnan(x)]

Example 4: remove rows or columns with NaN value

df.dropna()     #drop all rows that have any NaN values
df.dropna(how='all')

Example 5: drop na pandas

>>> df.dropna(subset=['name', 'born'])
       name        toy       born
1    Batman  Batmobile 1940-04-25

Example 6: python remove nan rows

df = df[df['my_var'].notna()]

Tags:

Misc Example