Project

Exploratory Data Analysis using a Dataset

import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn import linear_model
from math import floor
import nbconvert
from scipy.stats import trim_mean

titanic = pd.read_csv("titanic.csv")

# Check the type of data
print ("Type : ", type(titanic), "\n\n")

# Printing Top 10 Records
print ("Head -- \n", titanic.head(10))
# Printing last 10 Records
print ("\n\n Tail -- \n", titanic.tail(10))

# Printing the Top 5 data
titanic.head(5)

# Printing the Tail 5 data
titanic.tail(5)

#Checking the NULL values
titanic.isnull().sum()

titanic.describe()
titanic.median()
np.mean(titanic)

# Countplot
sns.catplot(x ="Sex", hue ="Survived", kind ="count", data = titanic)

# Group the dataset by Pclass and Survived and then unstack them
group = titanic.groupby(['Pclass', 'Survived'])
pclass_survived = group.size().unstack()

# Heatmap - Color encoded 2D representation of data.
sns.heatmap(pclass_survived, annot = True, fmt ="d")

# Violinplot Displays distribution of data
# across all levels of a category.
sns.violinplot(x ="Sex", y ="Age", hue ="Survived", data = titanic, split = True)

# Adding a column Family_Size
titanic['Family_Size'] = 0
titanic['Family_Size'] = titanic['Parch']+titanic['SibSp']

# Adding a column Alone
titanic['Alone'] = 0
titanic.loc[titanic.Family_Size == 0, 'Alone'] = 1

# Factorplot for Family_Size
sns.factorplot(x ='Family_Size', y ='Survived', data = titanic)

# Factorplot for Alone
sns.factorplot(x ='Alone', y ='Survived', data = titanic)

# Divide Fare into 4 bins
titanic['Fare_Range'] = pd.qcut(titanic['Fare'], 5)

# Barplot - Shows approximate values based
# on the height of bars.
sns.barplot(x ='Fare_Range', y ='Survived', data = titanic)

# Countplot
sns.catplot(x ='Embarked', hue ='Survived', kind ='count', col ='Pclass', data = titanic)
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.