pandas中 isnull 和 any 的联合使用

时间:2025-02-10 18:56:01
# 查看各列是否存在空值,True表示有空值 movie_data.isnull().any(axis=0) ## output id False imdb_id True popularity False budget False revenue False original_title False cast True homepage True director True tagline True keywords True overview True runtime False genres True production_companies True release_date False vote_count False vote_average False release_year False budget_adj False revenue_adj False dtype: bool # 含有空值的列数 movie_data.isnull().any(axis=0).sum() ## output 9 # 查看各行是否存在空值 movie_data.isnull().any(axis=1) ## output 0 False 1 False 2 False 3 False 4 False 5 False ··· 10860 True 10861 True 10862 True 10863 True 10864 True 10865 True Length: 10866, dtype: bool # 含有空值的行数 movie_data.isnull().any(axis=1).sum() ## output 8874