Professional Documents
Culture Documents
DATA VISUALIZATION
Matplotlib
Out[ ]: survived pclass sex age sibsp parch fare embarked class who adult_male
... ... ... ... ... ... ... ... ... ... ... ..
file:///C:/Users/nsoha/Downloads/assignment10HUNAIN.html 1/27
1/15/23, 5:00 PM assignment10HUNAIN
file:///C:/Users/nsoha/Downloads/assignment10HUNAIN.html 2/27
1/15/23, 5:00 PM assignment10HUNAIN
file:///C:/Users/nsoha/Downloads/assignment10HUNAIN.html 3/27
1/15/23, 5:00 PM assignment10HUNAIN
file:///C:/Users/nsoha/Downloads/assignment10HUNAIN.html 4/27
1/15/23, 5:00 PM assignment10HUNAIN
file:///C:/Users/nsoha/Downloads/assignment10HUNAIN.html 5/27
1/15/23, 5:00 PM assignment10HUNAIN
In [ ]: #Histogram
plt.hist(data['survived'])
plt.show()
#output contains only two bars as we have only one and zero in survived column
In [ ]: #Histogram
plt.hist(data['age'])
plt.show()
file:///C:/Users/nsoha/Downloads/assignment10HUNAIN.html 6/27
1/15/23, 5:00 PM assignment10HUNAIN
file:///C:/Users/nsoha/Downloads/assignment10HUNAIN.html 7/27
1/15/23, 5:00 PM assignment10HUNAIN
survived pclass sex age sibsp parch fare embarked class who ad
Out[ ]:
ult_male deck embark_town alive alone
1 1 female 24.0 0 0 69.3000 C First woman Fa
lse B Cherbourg yes True 2
58.0 0 0 26.5500 S First woman Fa
lse C Southampton yes True 1
49.0 0 0 25.9292 S First woman Fa
lse D Southampton yes True 1
1 0 76.7292 C First woman Fa
lse D Cherbourg yes False 1
50.0 0 1 247.5208 C First woman Fa
lse B Cherbourg yes False 1
..
16.0 0 0 86.5000 S First woman Fa
lse B Southampton yes True 1
1 39.4000 S First woman Fa
lse D Southampton yes False 1
57.9792 C First woman Fa
lse B Cherbourg
yes False 1
17.0 1 0 57.0000 S First woman Fa
lse B Southampton yes False 1
3 male 32.0 0 0 8.0500 S Third man Tr
ue E Southampton yes True 1
Length: 181, dtype: int64
24.00 30
Out[ ]:
22.00 27
18.00 26
19.00 25
28.00 25
..
36.50 1
55.50 1
0.92 1
23.50 1
74.00 1
Name: age, Length: 88, dtype: int64
In [ ]: data['age'].value_counts().plot(kind='bar')
#this graph is so skewed as we have many ages
<AxesSubplot:>
Out[ ]:
file:///C:/Users/nsoha/Downloads/assignment10HUNAIN.html 8/27
1/15/23, 5:00 PM assignment10HUNAIN
In [ ]: data['survived'].value_counts().plot(kind='bar')
#bar graph for survived is not skewed as we have only 1 and 0 in survived column
<AxesSubplot:>
Out[ ]:
<AxesSubplot:ylabel='count'>
Out[ ]:
file:///C:/Users/nsoha/Downloads/assignment10HUNAIN.html 9/27
1/15/23, 5:00 PM assignment10HUNAIN
In [ ]: sns.countplot(data['age'])
#again we obtained a very skew graph
file:///C:/Users/nsoha/Downloads/assignment10HUNAIN.html 10/27
1/15/23, 5:00 PM assignment10HUNAIN
In [ ]: sns.countplot(data['survived'])
#not skewed graph
file:///C:/Users/nsoha/Downloads/assignment10HUNAIN.html 11/27
1/15/23, 5:00 PM assignment10HUNAIN
<AxesSubplot:xlabel='survived', ylabel='count'>
Out[ ]:
In [ ]: #scatter plot between survived & age with hue pclass
sns.scatterplot(data=data,x='survived',y='age',hue='pclass')
file:///C:/Users/nsoha/Downloads/assignment10HUNAIN.html 12/27
1/15/23, 5:00 PM assignment10HUNAIN
<AxesSubplot:xlabel='survived', ylabel='age'>
Out[ ]:
<AxesSubplot:xlabel='age', ylabel='fare'>
Out[ ]:
file:///C:/Users/nsoha/Downloads/assignment10HUNAIN.html 13/27
1/15/23, 5:00 PM assignment10HUNAIN
<AxesSubplot:xlabel='sex', ylabel='fare'>
Out[ ]:
<AxesSubplot:xlabel='sex', ylabel='fare'>
Out[ ]:
file:///C:/Users/nsoha/Downloads/assignment10HUNAIN.html 14/27
1/15/23, 5:00 PM assignment10HUNAIN
plt.figure(figsize=(10,15))
plt.show()
array([[<AxesSubplot:title={'center':'survived'}>,
Out[ ]:
<AxesSubplot:title={'center':'pclass'}>],
[<AxesSubplot:title={'center':'age'}>,
<AxesSubplot:title={'center':'sibsp'}>],
[<AxesSubplot:title={'center':'parch'}>,
<AxesSubplot:title={'center':'fare'}>]], dtype=object)
file:///C:/Users/nsoha/Downloads/assignment10HUNAIN.html 15/27
1/15/23, 5:00 PM assignment10HUNAIN
<AxesSubplot:xlabel='sex', ylabel='fare'>
Out[ ]:
In [ ]: #boxenplot
sns.boxenplot(data=data,x='sex',y='fare',hue='pclass')
file:///C:/Users/nsoha/Downloads/assignment10HUNAIN.html 16/27
1/15/23, 5:00 PM assignment10HUNAIN
<AxesSubplot:xlabel='sex', ylabel='fare'>
Out[ ]:
In [ ]: #Swarmplot
sns.swarmplot(data=data,x='sex',y='fare',hue='pclass')
file:///C:/Users/nsoha/Downloads/assignment10HUNAIN.html 17/27
1/15/23, 5:00 PM assignment10HUNAIN
In [ ]: #Stripplot
sns.stripplot(data=data,x='sex',y='fare',hue='pclass')
<AxesSubplot:xlabel='sex', ylabel='fare'>
Out[ ]:
In [ ]: #heatmap
corr=data.corr()
sns.heatmap(corr)
#range of heatmap (-1 - +1)
file:///C:/Users/nsoha/Downloads/assignment10HUNAIN.html 18/27
1/15/23, 5:00 PM assignment10HUNAIN
<AxesSubplot:>
Out[ ]:
In [ ]: #boxplot
sns.boxplot(data=data,x='sex',y='fare',hue='who')
<AxesSubplot:xlabel='sex', ylabel='fare'>
Out[ ]:
file:///C:/Users/nsoha/Downloads/assignment10HUNAIN.html 19/27
1/15/23, 5:00 PM assignment10HUNAIN
In [ ]: #swarmplot
sns.swarmplot(data=data,x='sex',y='fare',hue='who')
file:///C:/Users/nsoha/Downloads/assignment10HUNAIN.html 20/27
1/15/23, 5:00 PM assignment10HUNAIN
In [ ]: #boxenplot
sns.boxenplot(data=data,x='sex',y='fare',hue='who')
<AxesSubplot:xlabel='sex', ylabel='fare'>
Out[ ]:
In [ ]: #stripplot
sns.stripplot(data=data,x='sex',y='fare',hue='who')
file:///C:/Users/nsoha/Downloads/assignment10HUNAIN.html 21/27
1/15/23, 5:00 PM assignment10HUNAIN
<AxesSubplot:xlabel='sex', ylabel='fare'>
Out[ ]:
In [ ]: #violinplot
sns.violinplot(data=data,x='sex',y='fare',hue='who')
<AxesSubplot:xlabel='sex', ylabel='fare'>
Out[ ]:
In [ ]: #lmplot
sns.lmplot(data=data,x='age',y='fare',hue='who')
file:///C:/Users/nsoha/Downloads/assignment10HUNAIN.html 22/27
1/15/23, 5:00 PM assignment10HUNAIN
<seaborn.axisgrid.FacetGrid at 0x207e6b6b760>
Out[ ]:
<seaborn.axisgrid.FacetGrid at 0x207e6de1190>
Out[ ]:
file:///C:/Users/nsoha/Downloads/assignment10HUNAIN.html 23/27
1/15/23, 5:00 PM assignment10HUNAIN
<AxesSubplot:xlabel='age', ylabel='fare'>
Out[ ]:
file:///C:/Users/nsoha/Downloads/assignment10HUNAIN.html 24/27
1/15/23, 5:00 PM assignment10HUNAIN
Out[ ]: survived pclass sex age sibsp parch fare embarked class who adult_male de
In [ ]: #scatterplot
sns.scatterplot(data=data,x='age',y='age_growth',hue='who')
<AxesSubplot:xlabel='age', ylabel='age_growth'>
Out[ ]:
file:///C:/Users/nsoha/Downloads/assignment10HUNAIN.html 25/27
1/15/23, 5:00 PM assignment10HUNAIN
Out[ ]: survived pclass sex age sibsp parch fare embarked class who adult_male de
In [ ]: #boxenplot
sns.boxenplot(data=data,x='fare',y='age_growth',hue='age_label')
<AxesSubplot:xlabel='fare', ylabel='age_growth'>
Out[ ]:
file:///C:/Users/nsoha/Downloads/assignment10HUNAIN.html 26/27
1/15/23, 5:00 PM assignment10HUNAIN
In [ ]: #boxenplot
sns.boxenplot(data=data,y='age_growth',x='sex',hue='age_label')
<AxesSubplot:xlabel='sex', ylabel='age_growth'>
Out[ ]:
file:///C:/Users/nsoha/Downloads/assignment10HUNAIN.html 27/27