application_vnd.jupyter.stderr_output_1.png
import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
pd.pandas.set_option('display.max_columns', None)

data = pd.read_csv('houseprice.csv')

vars_with_na = [var for var in data.columns if data[var].isnull().sum() > 1]

def analyse_na_value(df, var):
    df = df.copy()
    df[var] = np.where(df[var].isnull(), 1, 0)
for var in vars_with_na:
    analyse_na_value(data, var)

num_vars = [var for var in data.columns if data[var].dtypes != 'O']

year_vars = [var for var in num_vars if 'Yr' in var or 'Year' in var]
year_vars

def analyse_year_vars(df, var):
    df = df.copy()
    df[var] = df['YrSold'] - df[var]
for var in year_vars:
    if var != 'YrSold':
        analyse_year_vars(data, var)

discrete_vars = [var for var in num_vars if len(data[var].unique()) < 20 and var not in year_vars + ['Id']]

def analyse_discrete(df, var):
    df = df.copy()
for var in discrete_vars:
    analyse_discrete(data, var)

cont_vars = [var for var in num_vars if var not in discrete_vars + year_vars + ['Id']]

def analyse_continous(df, var):
    df = df.copy()
    df[var].hist(bins=20)
    plt.ylabel('Number of houses')
    plt.xlabel(var)
    plt.title(var)
    plt.show()
for var in cont_vars:
    analyse_continous(data, var)