drop if nan in column
df = df[df['EPS'].notna()]
删除具有NaN值的行或列
df.dropna() #drop all rows that have any NaN values
df.dropna(how='all')
使用nan panda拖放列
>>> df.dropna(axis='columns')
name
0 Alfred
1 Batman
2 Catwoman
熊猫滴行与楠
import pandas as pd
df = pd.DataFrame({'values_1': ['700','ABC','500','XYZ','1200'],
'values_2': ['DDD','150','350','400','5000']
})
df = df.apply (pd.to_numeric, errors='coerce')
df = df.dropna()
df = df.reset_index(drop=True)
print (df)
从dataframe转换为list时删除nan值
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']]