You are on page 1of 6

In [6]: import pandas as pd

import seaborn as sns


sns.set(color_codes=True)

In [9]: data=pd.read_csv("C:/Users/ASUS/Downloads/tips.csv")

In [10]: data.head()

Out[10]: Payment
total_bill tip gender smoker day time size price_per_person Payer Name CC Number
ID

Christy
0 16.99 1.01 Female No Sun Dinner 2 8.49 3.560330e+15 Sun2959
Cunningham

Douglas
1 10.34 1.66 Male No Sun Dinner 3 3.45 4.478070e+15 Sun4608
Tucker

Travis
2 21.01 3.50 Male No Sun Dinner 3 7.00 6.011810e+15 Sun4458
Walters

Nathaniel
3 23.68 3.31 Male No Sun Dinner 2 11.84 4.676140e+15 Sun5260
Harris

4 24.59 3.61 Female No Sun Dinner 4 6.15 Tonya Carter 4.832730e+15 Sun2251

In [13]: import matplotlib.pyplot as plt

In [14]: #Scatter plots are used to observe relationships between variables and
#uses dots to represent the relationship between them.
#The scatter() method in the matplotlib library is used to draw a scatter plot.

plt.scatter(data['day'], data['tip'])
plt.title('scatter plot')
plt.xlabel('Day')
plt.ylabel('tip')
plt.show()

In [19]: plt.scatter(data['day'], data['tip'], c=data['size'],


s=data['total_bill'])
plt.xlabel('Day')
plt.ylabel('Tip')
plt.show()
In [20]: #Bar Chart
#A bar plot or bar chart is a graph that represents the category of data with
#rectangular bars with lengths and heights that is proportional to the values
#which they represent. It can be created using the bar() method.

plt.bar(data['day'], data['tip'])
plt.title("Bar Chart")
plt.xlabel('Day')
plt.ylabel('Tip')
plt.show()

In [21]: #Histogram

#A histogram is basically used to represent data in the form of some groups.


#It is a type of bar plot where the X-axis represents the bin ranges while
#the Y-axis gives information about frequency. The hist() function is used
#to compute and create a histogram. In histogram, if we pass categorical
#data then it will automatically compute the frequency of that data i.e.
#how often each value occurred.

plt.hist(data['total_bill'])
plt.title("Histogram")
plt.show()
In [22]: #Line Plot

#Line Plot in Seaborn plotted using the lineplot() method. In this, we can
#pass only the data argument also.

sns.lineplot(x='day', y='tip', data=data)


plt.show()

In [23]: sns.lineplot(data=data.drop(['total_bill'], axis=1))


<AxesSubplot:>
Out[23]:

In [24]: #Bar Plot


#Bar Plot in Seaborn can be created using the barplot() method.

sns.barplot(x='day',y='tip', data=data, hue='gender')

plt.show()

In [27]: #Histogram

#The histogram in Seaborn can be plotted using the histplot() function.

sns.histplot(x='total_bill', data=data, kde=True, hue='gender')

<AxesSubplot:xlabel='total_bill', ylabel='Count'>
Out[27]:

In [30]: data.tail(250)

Out[30]: Payment
total_bill tip gender smoker day time size price_per_person Payer Name CC Number
ID

Christy
0 16.99 1.01 Female No Sun Dinner 2 8.49 3.560330e+15 Sun2959
Cunningham

Douglas
1 10.34 1.66 Male No Sun Dinner 3 3.45 4.478070e+15 Sun4608
Tucker

Travis
2 21.01 3.50 Male No Sun Dinner 3 7.00 6.011810e+15 Sun4458
Walters

Nathaniel
3 23.68 3.31 Male No Sun Dinner 2 11.84 4.676140e+15 Sun5260
Harris
4 24.59 3.61 Female No Sun Dinner 4 6.15 Tonya Carter 4.832730e+15 Sun2251

... ... ... ... ... ... ... ... ... ... ... ...

Michael
239 29.03 5.92 Male No Sat Dinner 3 9.68 5.296070e+15 Sat2657
Avila

Monica
240 27.18 2.00 Female Yes Sat Dinner 2 13.59 3.506810e+15 Sat1766
Sanders

241 22.67 2.00 Male Yes Sat Dinner 2 11.34 Keith Wong 6.011890e+15 Sat3880

Dennis
242 17.82 1.75 Male No Sat Dinner 2 8.91 4.375220e+12 Sat17
Dixon

Michelle
243 18.78 3.00 Female No Thur Dinner 2 9.39 3.511450e+15 Thur672
Hardin

244 rows × 11 columns

In [34]: # Here, Correlation matrix shows:


# the relationship among explanatory variables as well as,
#the relationship between the dependent varibale with each of the explanatory
#variables
sns.pairplot(data)

<seaborn.axisgrid.PairGrid at 0x1c296f1fe50>
Out[34]:
In [ ]:

You might also like