微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

并非所有变量都显示在 jupyter notebook 的条形图中

如何解决并非所有变量都显示在 jupyter notebook 的条形图中

我正在尝试将缺失值的变量引入为 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 列。我想知道我做错了什么。

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。