Comparison pd.isna
, math.isnan
and np.isnan
and their flexibility dealing with different type of objects.
The table below shows if the type of object can be checked with the given method:
+------------+-----+---------+------+--------+------+
| Method | NaN | numeric | None | string | list |
+------------+-----+---------+------+--------+------+
| pd.isna | yes | yes | yes | yes | yes |
| math.isnan | yes | yes | no | no | no |
| np.isnan | yes | yes | no | no | yes | df.isnull[].any[].any[]
True
- Tùy chọn 2 :
df.isnull[].sum[].sum[]
- Điều này trả về một số nguyên của tổng sốNaN
giá trị:
Điều này hoạt động theo cách tương tự như trước .any[].any[]
, bằng cách trước tiên đưa ra tổng của số
lượng NaN
giá trị trong một cột, sau đó là tổng của các giá trị đó:
df.isnull[].sum[]
0 0
1 2
2 0
3 1
4 0
5 2
dtype: int64
Cuối cùng, để có được tổng số giá trị NaN trong DataFrame:
df.isnull[].sum[].sum[]
5
128 hữu ích 0 bình luận chia sẻ