pandas中 isnull() 和 any() 的联合使用

# 查看各列是否存在空值,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

猜你喜欢

转载自blog.csdn.net/guo_ya_nan/article/details/81013510