pandas 判断指定列是否有(全部是)空值(NaN)
首先定义一个数据表:
a = pd.DataFrame({'name':['Tom','Amy','John','George'],
'sex':['male','female',np.nan,'male'],
'number':['SA1001','SA1002','SA1003','SA1004'],
'grade':[np.nan,np.nan,np.nan,np.nan]})
- 判断某列是否有NaN
df['col'].isnull().any()
- 判断某列是否全部为NaN
df['col'].isnull().all()
- 查看表格哪些列是否全为NaN
df.isnull().all()