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

import warnings

import pandas as pd, numpy as np, seaborn as sns, matplotlib.pyplot as plt
import warnings
warnings.simplefilter('ignore')
pd.set_option('display.max_columns', None)

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

df = df.drop('Cabin', axis=1)
df = df.dropna(subset=['Age', 'Embarked'])
bins = [0, 13, 18, 40, 50, 60, 70, 120]
labels = ['0-12', '13-18', '18-39', '40-49', '50-59', '60-70', '70+']
df['agegroup'] = pd.cut(df.Age, bins, labels=labels, include_lowest=True)
df = df.drop('Age', axis=1)
colstodrop = ['PassengerId', 'Name', 'Ticket']
df = df.drop(colstodrop, axis=1)

dummies = pd.get_dummies(df[['Sex', 'Embarked', 'agegroup']])
df = pd.concat([df, dummies], axis=1)
df = df.drop(['Sex', 'Embarked', 'agegroup'], axis=1)

low = df['Fare'].quantile(0.05)
high = df['Fare'].quantile(0.95)
df = df[(df['Fare'] >= low) & (df['Fare'] <= high)]

print(df.Fare.describe([0.1, 0.25, 0.5, 0.75, 0.9, 0.95, 0.99]))