最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
pandas统计某一列或某一行的缺失值数目代码示例
时间:2022-06-25 01:13:47 编辑:袖梨 来源:一聚教程网
本篇文章小编给大家分享一下pandas统计某一列或某一行的缺失值数目代码示例,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
统计某一列或某一行的缺失值数目
1.使用isnull()
import pandas as pd
# 首先导入数据
df = pd.read_csv('123.csv' , encoding='gbk')
# 计算data每一行有多少个缺失值的值,即按行统计缺失值
rows_null = df.isnull().sum(axis=1)
# 下面则是按列统计缺失值
col_null = df.isnull().sum(axis=0)
#统计整个df的缺失值
all_null = df.isnull().sum().sum()
# 统计某一列的缺失值
idx_null = df['列名'].isnull().sum(axis=0)
2.使用count
import pandas as pd
# 首先导入数据
df = pd.read_csv('123.csv' , encoding='gbk')
# 计算data每一行有多少个非空的值,即按行统计非空值
rows_not_null = df.count(axis=1)
# 下面则是按列统计非空值
cols_not_null = df.count(axis=0)
cols_null = df.shape[1] - cols_not_null
# 统计某一列的非空值
col_not_null = df['列名'].count(axis=0)
利用pandas处理缺失值
处理缺失值
def missing_values(dataframe):
missing_ratio = (dataframe.isnull().sum() / len(dataframe))*100
missing_ratio = missing_ratio.drop(missing_ratio[missing_ratio == 0].index).sort_values(ascending=False)
missing_count = dataframe.isnull().sum()
missing_count = missing_count.drop(missing_count[missing_count == 0].index).sort_values(ascending=False)
info = pd.DataFrame({'Missing Ratio': missing_ratio, 'Missing Count': missing_count})
return info
相关文章
- 燕云十六声伞扇牵丝玉流派玩法攻略 10-26
- 燕云十六声被悬赏应对方法介绍说明 10-26
- 燕云十六声老金义父成就解锁方法分享 10-26
- 燕云十六声绳镖武学栗子游尘获取方法 10-26
- 燕云十六声不羡仙完全探索攻略分享 10-26
- 流放之路2换界石加工方法介绍说明 10-26