在做项目时遇到了一个错误:
#过滤出正常的工作经验值数据集合不正常的工作经验布尔值
dfExp=data.query('Experience>0')
negExp=data.Experience<0
mylist=data.loc[negExp]['ID'].tolist()
#对每一个工作经验为负的样本,用同年龄和教育程度的工作经验均值代替
for id in mylist:
age=data.query('ID==@id').Age.tolist()[0]
education=data.query('ID==@id').Education.tolist()[0]
df_filtered=dfExp.query('Age==@age and Education==@education')
exp=df_filtered['Experience'].median()
if exp is not np.nan:
exp=data.Experience.median()
data.loc[data.query('ID==@id').index,'Experience']=exp
print(data.Experience.describe())
sns.distplot(data.Experience)
上面这一段代码,目的是通过for循环把数据下Experience(工作经验)列中的异常值,即负值进行清洗,因为工作经验与年

在项目中,作者遇到Python数据处理时出现'nan'错误,尝试过滤负值工作经验并用中位数替换。经过排查,发现不是原始数据包含'nan',而是matplotlib库存在bug导致运行时报错。更新matplotlib库后问题解决。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



