text_plain_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

import pandas as pd
raw_data = pd.read_csv('../input/train.csv')

columns = raw_data.columns.tolist()
if 'Id' in columns:
    columns.remove('Id')

columns_with_null_values = []
for c in columns:
    f = c
    feature_name = str(f)
    has_null = str(any(raw_data[f].isnull().values))
    if has_null == 'True':
        columns_with_null_values.append(f)
        column_type = raw_data[f].dtype

for c in columns_with_null_values:
    counter = raw_data[c].value_counts(dropna=False)
    try:
        counts = counter[None]
    except:
        counts = counter[float('nan')]
    length = len(raw_data)
    usable = length - counts

column_names = raw_data.columns.drop('Id')
int_columns, float_columns, object_columns = ([], [], [])
for c in column_names:
    column_dtype = str(raw_data.dtypes[c])
    if column_dtype == 'int64':
        int_columns.append(c)
    elif column_dtype == 'object':
        object_columns.append(c)
    elif column_dtype == 'float64':
        float_columns.append(c)

numerical_columns, categorical_columns = ([], [])
temporal_columns = ['GarageYrBlt', 'YearBuilt', 'YearRemodAdd', 'MoSold', 'YrSold']
from_int = ['MSSubClass']
categorical_columns = object_columns + from_int + temporal_columns
numerical_columns = list(filter(lambda x: x not in temporal_columns + ['MSSubClass'], int_columns)) + list(filter(lambda x: x not in temporal_columns, float_columns))

bounded_columns = ['OverallQual', 'OverallCond']
binary_columns = []
for c in categorical_columns:
    classes = raw_data[c].unique()
    length = len(classes)
    if length == 2:
        binary_columns.append(c)

counting_columns = ['BsmtFullBath', 'BsmtHalfBath', 'FullBath', 'HalfBath', 'BedroomAbvGr', 'KitchenAbvGr', 'TotRmsAbvGrd', 'Fireplaces', 'GarageCars']

month_code = raw_data['MoSold'].unique()
def get_season(month_code):
    m = month_code
    if m in [3, 4, 5]:
        return 'Spring'
    elif m in [6, 7, 8]:
        return 'Summer'
    elif m in [9, 10, 11]:
        return 'Autumn'
    elif m in [12, 1, 2]:
        return 'Winter'
seasons_series = raw_data['MoSold'].apply(get_season)
seasons_series.name = 'season'

year_sold = raw_data['YrSold']
year_built = raw_data['YearBuilt']
house_age_series = year_sold.subtract(year_built)
house_age_series.name = 'HouseAge'

garage_year_built = raw_data['GarageYrBlt']
year_built = raw_data['YearBuilt']
garage_age_series = year_sold.subtract(garage_year_built)
garage_age_series.name = 'GarageAge'

year_remod_add = raw_data['YearRemodAdd']
year_built = raw_data['YearBuilt']
remod_recency_series = year_sold.subtract(year_remod_add)
remod_recency_series.name = 'RemodRecency'

recent_df = raw_data
recent_df = recent_df.assign(garage_age=garage_age_series)
recent_df = recent_df.assign(remod_recency=remod_recency_series)
recent_df = recent_df.assign(house_age=house_age_series)
recent_df = recent_df.assign(season=seasons_series)
categorical_columns = categorical_columns + ['season']
numerical_columns = numerical_columns + ['garage_age', 'remod_recency', 'house_age']
recent_df[categorical_columns] = recent_df[categorical_columns].fillna('None')

import matplotlib.pyplot as plt

plt.style.use("ggplot")
    
for c in (categorical_columns + bounded_columns + counting_columns):
    
    if c in temporal_columns and c != "MoSold":
        continue

    means = recent_df[["SalePrice",c]].groupby(c).mean().sort_values("SalePrice",ascending=False)
    errors = recent_df[["SalePrice",c]].groupby(c).std()
    barplot = means.plot.bar(yerr=errors)
    
    plt.title(c)
    plt.show()

data = recent_df
iv = 'CentralAir'
dv = 'SalePrice'
for c in categorical_columns + bounded_columns + counting_columns:
    if c in temporal_columns:
        continue
    data.boxplot(column=dv, by=c, vert=True, grid=True)
    plt.xlabel('Sale Price')
    plt.ylabel(c)
    plt.title('')
    plt.suptitle('')
    plt.show()