问答 · ANSWER
如何识别缺失值?
直接回答
使用 pandas 的 isnull() 方法检测数据中的缺失值,并结合 any() 方法快速定位存在缺失值的行或列。
关键要点
- pandas 中缺失值通常由 NaN 表示。
- isnull() 方法返回布尔对象,标记每个元素是否为缺失值。
- any(axis=0) 检查哪些列包含缺失值。
- any(axis=1) 检查哪些行包含缺失值。
- 识别缺失值是数据清洗的第一步。
怎么选 / 怎么做
1. 使用 df.isnull() 检测数据中的每个元素,返回布尔值 DataFrame。
2. 使用 df.isnull().any()(默认 axis=0)检查哪些列存在缺失值。
3. 使用 df.isnull().any(axis=1) 检查哪些行存在缺失值。
常见问题
isnull() 返回什么?
返回布尔对象,True 表示该位置是缺失值。
如何快速找到有缺失值的列?
使用 df.isnull().any()。
如何快速找到有缺失值的行?
使用 df.isnull().any(axis=1)。