最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

pandas如何統(tǒng)計(jì)某一列或某一行的缺失值數(shù)目

 更新時(shí)間:2022年05月12日 11:43:24   作者:WGS.  
這篇文章主要介紹了pandas如何統(tǒng)計(jì)某一列或某一行的缺失值數(shù)目,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

統(tǒng)計(jì)某一列或某一行的缺失值數(shù)目

1.使用isnull()

import pandas as pd

# 首先導(dǎo)入數(shù)據(jù)
df = pd.read_csv('123.csv' , encoding='gbk')

# 計(jì)算data每一行有多少個(gè)缺失值的值,即按行統(tǒng)計(jì)缺失值
rows_null = df.isnull().sum(axis=1)?

# 下面則是按列統(tǒng)計(jì)缺失值
col_null = df.isnull().sum(axis=0)

#統(tǒng)計(jì)整個(gè)df的缺失值
all_null = df.isnull().sum().sum()

# 統(tǒng)計(jì)某一列的缺失值
idx_null = df['列名'].isnull().sum(axis=0)

2.使用count

import pandas as pd

# 首先導(dǎo)入數(shù)據(jù)
df = pd.read_csv('123.csv' , encoding='gbk')

# 計(jì)算data每一行有多少個(gè)非空的值,即按行統(tǒng)計(jì)非空值
rows_not_null = df.count(axis=1)?

# 下面則是按列統(tǒng)計(jì)非空值
cols_not_null = df.count(axis=0)
cols_null = df.shape[1] - cols_not_null

# 統(tǒng)計(jì)某一列的非空值
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

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

民乐县| 桃江县| 额敏县| 临高县| 高台县| 邛崃市| 吉安市| 壤塘县| 新泰市| 井冈山市| 大化| 林芝县| 龙川县| 镇康县| 松潘县| 平泉县| 噶尔县| 宜城市| 诏安县| 奉节县| 诸城市| 安多县| 临江市| 公主岭市| 新营市| 永泰县| 吉安市| 楚雄市| 称多县| 兴和县| 远安县| 宝鸡市| 镇远县| 定结县| 甘洛县| 贵阳市| 郴州市| 海宁市| 晋江市| 苏尼特右旗| 富裕县|