首页 > 解决方案 > Python Pandas - notnull() 和 ~notnull() 不是互斥的

问题描述

当我运行以下代码时:

maintenance_items['Last order'][maintenance_items['Last order'].notnull()].count()

我得到的答案是 16522(19313 中)。这似乎是正确的。但是,如果我使用以下任何代码来检查相反的情况:

maintenance_items['Last order'][~maintenance_items['Last order'].notnull()].count() 

或者

maintenance_items['Last order'][maintenance_items['Last order'].isnull()].count()

或者

maintenance_items['Last order'][maintenance_items['Last order'].isna()].count()

我得到的答案是 0(19313 中)。我期待 2791(19313 减去 16522)。为什么上面的 notnull() 和相反的语句不相互排斥有充分的理由吗?

标签: pythonpandasconditional-statements

解决方案


推荐阅读