處理pandas數據中的NaN值
- pd.dropna()
- pd.fillna()
- pd.isnull()
pd.dropna() 是直接刪除包含NaN的列
或者行
df.dropna(
axis=0, # 0: 對行進行操作; 1: 對列進行操作
how='any' # 'any': 只要存在 NaN 就 drop 掉; 'all': 必須全部是 NaN 才 drop
)
pd.fillna() 是填充NaN,比如可以填充爲0或者用其他列代替
# 填充爲0
pd.fillna(0)
# 用其他列的值代替
pd.fillna(pd['other'])
pd.isnull() 是判斷數據中是否還包含有NaN