Data¶
In [2]:
titanic = pd.read_csv("titanic.csv")
In [3]:
print(titanic.head())
In [4]:
titanic.shape
Out[4]:
In [11]:
cols = ['Survived', 'Pclass', 'Sex', 'Age', 'SibSp', 'Parch', 'Fare', 'Embarked']
titanic = titanic[cols].dropna()
Removed unwanted columns¶
In [12]:
titanic.head()
Out[12]:
Visualizing using seaborn¶
Histogram¶
In [19]:
sns.distplot(titanic["Fare"])
Out[19]:
In [20]:
sns.distplot(titanic["Age"])
Out[20]:
In [16]:
plt.boxplot(titanic["Age"])
Out[16]:
Generating a kernal density plot¶
In [22]:
sns.kdeplot(titanic["Age"], shade= True)
plt.xlabel("Age")
Out[22]:
Conditional distribution using single condition¶
In [31]:
g = sns.FacetGrid(titanic, col = "Survived", size = 5)
g.map(sns.kdeplot, "Age")
Out[31]:
In [32]:
g = sns.FacetGrid(titanic, col = "Pclass",size = 5)
g.map(sns.kdeplot,"Age")
Out[32]:
Creating a Conditional Plot using two conditions¶
Tip : use row parameter
In [33]:
g = sns.FacetGrid(titanic, row = "Pclass",col = "Survived", size = 5)
g.map(sns.kdeplot, "Age")
Out[33]:
Creating a Conditional Plot using three conditions¶
Tip: use hue
In [39]:
g = sns.FacetGrid(titanic, row = "Pclass", col = "Survived", hue = "Sex", size = 5)
g.map(sns.kdeplot, "Age", shade = True)
g.add_legend()
Out[39]:
In [ ]:
No comments :
Post a Comment