时间:2022-09-01 09:26:02 | 栏目:Python代码 | 点击:次
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)
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)
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