import os
import pandas as pd
os.chdir(r'D:\pycharm程序文件\练习1')
def miss_column(data):
"""
不能直接用value_counts()来计算比率, 即data.isnull().value_counts() 运行会发生如下错误
'DataFrame' object has no attribute 'value_counts'
"""
miss_num = data.isnull().sum() # 计算缺失个数
num = data.isnull().count() # 计算每一列总数
miss_rate = miss_num/num # 计算缺失值占比
return miss_num,num,miss_rate
if __name__== '__main__':
data = pd.read_excel('data.xlsx')
miss_num, num, miss_rate = miss_column(data)
print(miss_num, num, miss_rate)
python 表格作为实参传入函数的方法; 缺失值和缺失率计算
最新推荐文章于 2022-04-13 14:38:19 发布