text_plain_output_1.png
import matplotlib.pyplot as plt

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

app_train = pd.read_csv('../input/application_train.csv')

app_test = pd.read_csv('../input/application_test.csv')

def missing_values_table(df):
    """
    Function to calculate missing values by column
    Arguments:
        df: dataframe
    Output:
        miss_val_table_renamed_cols: dataframe with missing values
    """
    miss_value = df.isnull().sum()
    miss_value_pct = 100 * df.isnull().sum() / len(df)
    miss_val_table = pd.concat([miss_value, miss_value_pct], axis=1)
    miss_val_table_renamed_cols = miss_val_table.rename(columns={0: 'Missing Values', 1: '% of Total Values'})
    miss_val_table_renamed_cols = miss_val_table_renamed_cols[miss_val_table_renamed_cols.iloc[:, 1] != 0].sort_values('% of Total Values', ascending=False).round(1)
    return miss_val_table_renamed_cols

app_train.dtypes.value_counts()

app_train.select_dtypes('object').apply(pd.Series.nunique, axis=0)

app_train = pd.get_dummies(app_train)
app_test = pd.get_dummies(app_test)

train_labels = app_train['TARGET']
app_train, app_test = app_train.align(app_test, join='inner', axis=1)
app_train['TARGET'] = train_labels

app_train['DAYS_EMPLOYED_ANOM'] = app_train['DAYS_EMPLOYED'] == 365243
app_train['DAYS_EMPLOYED'].replace({365243: np.nan}, inplace=True)

app_test['DAYS_EMPLOYED_ANOM'] = app_test['DAYS_EMPLOYED'] == 365243
app_test['DAYS_EMPLOYED'].replace({365243: np.nan}, inplace=True)

correlations = app_train.corr()['TARGET'].sort_values()

plt.style.use('fivethirtyeight')

plt.ylabel = 'Density'
plt.title = 'Distribution of Ages'

age_data = app_train[['TARGET', 'DAYS_BIRTH']]
age_data['YEARS_BIRTH'] = age_data['DAYS_BIRTH'] / 365
age_data['YEARS_BINNED'] = pd.cut(age_data['YEARS_BIRTH'], bins=np.linspace(20, 70, num=11))
age_data.head()