python - 计算 pandas DataFrame 中的所有 NaN
问题描述
我正在尝试计算 pandas 系列中的 NaN 元素(数据类型类 'numpy.float64'),以了解有多少数据类型是类 'pandas.core.series.Series'
这是为了计算熊猫系列中的空值
import pandas as pd
oc=pd.read_csv(csv_file)
oc.count("NaN")
我的预期输出为oc,count("NaN")
7 但它显示'Level NaN must be same as name (None)'
解决方案
The argument to count
isn't what you want counted (it's actually the axis name or index).
You're looking for df.isna().values.sum()
(to count NaNs across the entire DataFrame), or len(df) - df['column'].count()
(to count NaNs in a specific column).
推荐阅读
- python-3.7 - 如何在 2 个单独的 python 列表中找到匹配项?
- javascript - 在 Aurelia 中根据 InnerHtml 更改背景颜色
- mysql - 为什么 Flask 从 Gunicorn 提供服务时拒绝关闭与数据库的连接?
- java - Activiti 的 RuntimeServiceImpl::startProcessInstanceByKey 在并发环境中无法正常工作
- mongodb - 根据另一个集合数据更新 mongo 字段
- php - PHP:如何在执行数组后从 HTML 输入标签中回显描述
- c++ - “新”创建实例的所有成员变量是否都存在于堆上而不是堆栈上?
- python - 通过字典中的 HTML 进行解析
- c++ - 在我的 c++ 应用程序中可以使用多少个线程
- docker - 使用绑定挂载运行容器化 MongoDB