Professional Documents
Culture Documents
8th LESSON (ANKUR - PROSCHOOL) - SEABORN - HTML
8th LESSON (ANKUR - PROSCHOOL) - SEABORN - HTML
#SNS has more statistical graphs like contour, heatmap, etc. These func
tionalities are not available in MATPLOTLIB
a = np.array([22,87,5,43,56,73,55,54,11,20,51,5,79,31,27])
plt.hist(a, bins = [0,20,40, 60,80,100], normed=True) #-Where Bins is t
he interval required on the x-axis
plt.title("histogram")
plt.show()
In [8]: tips=sns.load_dataset('tips')
In [10]: tips.info()
tips.describe()
<class 'pandas.core.frame.DataFrame'>
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
RangeIndex: 244 entries, 0 to 243
Data columns (total 7 columns):
total_bill 244 non-null float64
tip 244 non-null float64
sex 244 non-null category
smoker 244 non-null category
day 244 non-null category
time 244 non-null category
size 244 non-null int64
dtypes: category(4), float64(2), int64(1)
memory usage: 7.2 KB
Out[10]:
total_bill tip size
In [11]: tips
Out[11]:
total_bill tip sex smoker day time size
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
total_bill tip sex smoker day time size
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
total_bill tip sex smoker day time size
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
total_bill tip sex smoker day time size
In [22]: #Single Column histogram also depicting whether the data is normal or n
ot!!
sns.distplot(tips['total_bill'])
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
In [33]: #it is used to find the correlation & distribution of all quantitative
variables in a particular dataset
sns.pairplot(tips)
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
In [35]: #in case we want to see the graph between two variables only, use diffe
rent kinds of 'kind'. It is 2D graph
sns.jointplot(x='total_bill', y='tip', data=tips, kind='reg')
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
In [46]: sns.jointplot(x='total_bill', y='tip', data=tips, kind='hex')
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
In [43]: #hue adds an additional varaibale in the 2D pairplot, where the data is
distinguished based on the categorical variable
sns.pairplot(tips, hue='day')
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
In [48]: #DIFFERENT CHARTS BASED ON CATEGORICAL VARIABLE
g=sns.FacetGrid(tips,col='smoker', row='time')
g.map(plt.hist, 'total_bill')
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
In [49]: g=sns.FacetGrid(tips,col='smoker', row='day')
g.map(plt.hist, 'total_bill')
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
In [69]: ##HEATMAP - is used to calculate the correlation between two variable
h=tips.corr() #assigning a variable to it
h
Out[69]:
total_bill tip size
In [68]: sns.heatmap(h)
In [74]: sns.heatmap(h,cmap='Pastel1',annot=True)
#color ---> cmap
#datalabels ---> annot=True
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
In [75]: sns.heatmap(h,cmap='coolwarm',annot=True)
#color ---> cmap
#datalabels ---> annot=True
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD