how to remove nan in pandas code example

Example 1: remove nan from list python

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

Example 2: how to delete nan values in python

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

Example 3: how to filter out all NaN values in pandas df

#return a subset of the dataframe where the column name value != NaN 
df.loc[df['column name'].isnull() == False]

Example 4: drop na pandas

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

Example 5: python remove nan rows

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

Example 6: drop column with nan values

fish_frame = fish_frame.dropna(axis = 1, how = 'all')