DataFrame 求存在空值的行或列

非转置:df.isnull().any(),得到的每一列求any()计算的结果,输出为列的Series。

转置:df.isnull().T.any(),得到的每一行求any()计算的结果,输出为行的Series。

df = pd.DataFrame({‘age’:[10,None,30],’height’:[100,200,None]})
df
age height
0 10.0 100.0
1 NaN 200.0
2 30.0 NaN

df.isnull().any()
age True
height True
dtype: bool
df.isnull().any().index
Index([‘age’, ‘height’], dtype=’object’)
df[df.isnull().any().index].columns
Index([‘age’, ‘height’], dtype=’object’)

df.isnull().T.any()
0 False
1 True
2 True
dtype: bool
df[df.isnull().T.any()]
age height
1 NaN 200.0
2 30.0 NaN

Original: https://blog.csdn.net/lizz2276/article/details/117870712
Author: lizz2276
Title: DataFrame 求存在空值的行或列

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/676623/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球