text_html_output_1.png
from sklearn.impute import SimpleImputer

import pandas as pd

import pandas as pd
from sklearn.model_selection import train_test_split
data = pd.read_csv('../input/melbourne-housing-snapshot/melb_data.csv')
data.shape

pd.set_option('display.max_columns', None)

cols_with_missing = [col for col in X_train.columns if X_train[col].isnull().any()]
cols_with_missing

test_cols_with_missing = []
for col in X_train.columns:
    if X_train[col].isnull().any():
        test_cols_with_missing.append(col)
test_cols_with_missing

reduced_X_train = X_train.drop(cols_with_missing, axis=1)
reduced_X_valid = X_valid.drop(cols_with_missing, axis=1)

from sklearn.impute import SimpleImputer
my_imputer = SimpleImputer()
imputed_X_train = pd.DataFrame(my_imputer.fit_transform(X_train))
imputed_X_valid = pd.DataFrame(my_imputer.transform(X_valid))

imputed_X_train.columns = X_train.columns
imputed_X_valid.columns = X_valid.columns

X_train_plus = X_train.copy()
X_valid_plus = X_valid.copy()

X_train_full.shape

X_valid_full.shape

X_valid_full.columns

cols_with_missing = [col for col in X_train_full.columns if X_train_full[col].isnull().any()]
cols_with_missing

X_train_full.drop(cols_with_missing, axis=1, inplace=True)
X_valid_full.drop(cols_with_missing, axis=1, inplace=True)

low_cardinality_cols = [cname for cname in X_train_full.columns if X_train_full[cname].nunique() < 10 and X_train_full[cname].dtype == 'object']
low_cardinality_cols

numerical_cols = [cname for cname in X_train_full.columns if X_train_full[cname].dtype in ['int64', 'float64']]
numerical_cols

my_cols = low_cardinality_cols + numerical_cols
X_train = X_train_full[my_cols].copy()
X_valid = X_valid_full[my_cols].copy()
X_train.shape

cat_variables = X_train.dtypes == 'object'
type(cat_variables)

cat_variables[cat_variables]