text_html_output_1.png
from collections import Counter

import matplotlib.pyplot as plt

import numpy as np

import os

import pandas as pd

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

plt.style.available

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

def bar_plot(variable):
    """
    input: varible exmple: "sex"
    output: bar plot& value count
    """
    var = train_df[variable]
    varValue = var.value_counts()
    plt.xticks(varValue.index, varValue.index.values)

def plot_hist(variable):
    pass

def detectOutliers(df, features):
    outlier_indices = []
    for i in features:
        Q1 = np.percentile(df[i], 25)
        Q3 = np.percentile(df[i], 75)
        IQR = Q3 - Q1
        outlierStep = IQR * 1.5
        outlier_listCol = df[(df[i] < Q1 - outlierStep) | (df[i] > Q3 + outlierStep)].index
        outlier_indices.extend(outlier_listCol)
    outlier_indices = Counter(outlier_indices)
    multiple_outliers = list((i for i, k in outlier_indices.items() if k > 2))
    return multiple_outliers

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

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()