text_html_output_1.png
from collections import Counter

import matplotlib.pyplot as plt

import numpy as np # linear algebra

import os

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

import warnings

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
plt.style.use('seaborn-whitegrid')
from collections import Counter
import warnings
warnings.filterwarnings('ignore')
import os

train_df = pd.read_csv('/kaggle/input/titanic/train.csv')
test_df = pd.read_csv('/kaggle/input/titanic/test.csv')
test_PassengerId = test_df['PassengerId']

train_df.columns

def barplot(variable):
    """
    input : variable example: "Sex"
    output : barplot & value count
    """
    var = train_df[variable]
    varValue = var.value_counts()
    plt.xticks(varValue.index, varValue.index.values)

def plothist(variable):
    pass

def detect_outliers(df, features):
    outlier_indices = []
    for c in features:
        q1 = np.percentile(df[c], 25)
        q3 = np.percentile(df[c], 75)
        IQR = q3 - q1
        outlier_step = IQR * 1.5
        outlier_list_col = df[(df[c] < q1 - outlier_step) | (df[c] > q3 + outlier_step)].index
        outlier_indices.extend(outlier_list_col)
    outlier_indices = Counter(outlier_indices)
    multiple_outliers = list((i for i, v in outlier_indices.items() if v > 2))
    return multiple_outliers

train_df.loc[detect_outliers(train_df, ['Age', 'Parch', 'SibSp', 'Fare'])]

train_df = train_df.drop(detect_outliers(train_df, ['Age', 'Parch', 'SibSp', 'Fare']), axis=0).reset_index(drop=True)

train_df_len = len(train_df)
train_df = pd.concat([train_df, test_df], axis=0).reset_index(drop=True)

train_df.columns[train_df.isnull().any()]

train_df.isnull().sum()

train_df.boxplot(column='Fare', by='Embarked')
plt.show()