remove nan from column pandas code example

Example 1: how to delete na values in a dataframe

# if you want to delete rows containing NA values
df.dropna(inplace=True)

Example 2: drop if nan in column pandas

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

Example 3: drop null rows pandas

df.dropna()

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: when converting from dataframe to list delete nan values

a = [[y for y in x if pd.notna(y)] for x in df.values.tolist()]
print (a)
[['str', 'aad', 'asd'], ['ddd'], ['xyz', 'abc'], ['btc', 'trz', 'abd']]

Tags:

Misc Example