11

数据分析第九天

 3 years ago
source link: https://blog.csdn.net/qq_45858907/article/details/112251302
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

数据清洗的方法之空值的处理

isnull 判断是否为空值,notnull判断不是空值

data = pd.read_excel(r'人事终表 (1).xlsx')

print(data.isnull()) #isnull判断元素是否为空值,如果是就返回True,不是就返回Fasle
print(data.notnull().sum()) #判断元素不是空值的方法,
print(data['绩效'].notnull().sum()) #整个表中不是空值的数量

fillna查询到空值后,对空值的操作

#处理空值的方法
#查找空值,并且将空值填充为对应的值
 data.fillna({'应发数': 0,'部门':'实习','绩效':0,'发放时间':'2020-07工资'},inplace=True) #

dropna 删除空值的方法

#subset传入的是列表,
# axis表示删除的行或者列,how表示删除的方式是与(all)(劝为空再删)还是或(any)(有空值就删)
# thresh=6 表死非空值数量<6,则删除
#subset=['姓名','应发数','绩效',]表示删除的时候,可以根据指定的列中的缺失情况进行判断
data.dropna(axis=0,how='any',subset=['姓名','应发数','绩效',],thresh=6 ,inplace=True)

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK