问题描述
我正在尝试将缺失值的变量引入为 1,并将原始数据集中的值为 0。以查看缺失值对房屋预测的影响。
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
house_data=pd.read_csv("/home/udemy/houseprice.csv")
#we evaluate the price of a house for those cases where the information is missing,for each variable
def analyse_na_value(df,var):
# we indicate as a variable as 1 where the observation is missing
# we indicate as 0 where the observation has a real value
df[var] = np.where(df[var].isnull(),1,0)
#print(df[var].isnull())
# we calculate the mean saleprice where the information is missing or present
df.groupby(var)['SalePrice'].median().plot.bar()
plt.title(var)
plt.show()
for var in vars_with_na:
analyse_na_value(house_data,var)
在我正在关注的教程中,该图获得了两列:缺失值的列包含房屋的售价,而缺失值的列则包含房屋的售价。
但是,在我的 jupyter notebook 中,我只得到了图中省略了缺失值的图,而在教程中则有 2 列。我想知道我做错了什么。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)