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

train = pd.read_csv('/kaggle/input/titanic/train.csv')
test = pd.read_csv('/kaggle/input/titanic/test.csv')

data = pd.concat([train, test], axis=0, sort=False, ignore_index=True)
data.shape

data.set_index('PassengerId', inplace=True)

data.drop('Name', axis=1, inplace=True)

def find_missing_df(data):
    """
  Create dataframe showing which columns is missing values, amount and percent of missing values
  """
    missing_df = pd.DataFrame(columns=['Column_name', 'Total_missing_values', 'Percent_missing', 'data_types'])
    col_name_arr = []
    missing_value_arr = []
    percent_missing_arr = []
    dtypes_arr = []
    for col in data:
        if data[col].isna().sum() > 0:
            percent_missing = np.float(f'{data[col].isna().sum() / data.shape[0] * 100:.2f}')
            col_name_arr.append(col)
            dtypes_arr.append(data[col].dtypes)
            missing_value_arr.append(data[col].isna().sum())
            percent_missing_arr.append(percent_missing)
    missing_df['Column_name'] = col_name_arr
    missing_df['Total_missing_values'] = missing_value_arr
    missing_df['Percent_missing'] = percent_missing_arr
    missing_df['data_types'] = dtypes_arr
    return missing_df
missing_df = find_missing_df(data)
missing_df

num_cols = [feature for feature in data.columns if data[feature].dtypes != 'O']
num_cols

num_cols = num_cols[1:6]
num_cols

def plt_num_cols(data, num_var):
    for feature in num_var:
        f, (ax_box, ax_hist) = plt.subplots(2, sharex=True, gridspec_kw={'height_ratios': (0.15, 0.85)})
        f.set_figheight(3)
        f.set_figwidth(15)
        sns.boxplot(x=feature, data=data, ax=ax_box, orient='h')
        sns.histplot(data=data, x=feature, ax=ax_hist)
        plt.show()
plt_num_cols(data, num_cols)