跳到内容

pandas-use-of-dot-not-null (PD004)

源自 pandas-vet linter。

作用

检查 Pandas 对象上 .notnull 的使用。

为什么这不好?

在 Pandas API 中,.notna.notnull 是等效的。为了保持一致性,优先使用 .notna 而不是 .notnull

作为名称,.notna 更准确地反映了方法的行为,因为这些方法除了检查 None 值之外,还检查 NaNNaT 值。

示例

import pandas as pd

animals_df = pd.read_csv("animals.csv")
pd.notnull(animals_df)

建议改为

import pandas as pd

animals_df = pd.read_csv("animals.csv")
pd.notna(animals_df)

参考