B 4 Tips

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

4/14/24, 10:13 AM B_4_Tips

In [45]: #

In [46]: import pandas as pd

In [47]: df = pd.read_csv('tips_DV.csv')

In [48]: df

Out[48]: total_bill tip sex smoker day time size

0 16.99 1.01 Female No Sun Dinner 2

1 10.34 1.66 Male No Sun Dinner 3

2 21.01 3.50 Male No Sun Dinner 3

3 23.68 3.31 Male No Sun Dinner 2

4 24.59 3.61 Female No Sun Dinner 4

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

239 29.03 5.92 Male No Sat Dinner 3

240 27.18 2.00 Female Yes Sat Dinner 2

241 22.67 2.00 Male Yes Sat Dinner 2

242 17.82 1.75 Male No Sat Dinner 2

243 18.78 3.00 Female No Thur Dinner 2

244 rows × 7 columns

In [49]: df.rename(columns = {'size':'peoples'}, inplace = True)

In [50]: df.isna().sum()

total_bill 0
Out[50]:
tip 0
sex 0
smoker 0
day 0
time 0
peoples 0
dtype: int64

In [51]: col_var = df[['peoples','sex', 'smoker', 'day', 'time']]

for i in col_var:
print(i, df[i].unique())

peoples [2 3 4 1 6 5]
sex ['Female' 'Male']
smoker ['No' 'Yes']
day ['Sun' 'Sat' 'Thur' 'Fri']
time ['Dinner' 'Lunch']

In [52]: df.columns

Index(['total_bill', 'tip', 'sex', 'smoker', 'day', 'time', 'peoples'], dtype='obj


Out[52]:
ect')

localhost:8888/nbconvert/html/Desktop/DSBDA GROP B/Assignment 4/B_4_Tips.ipynb?download=false 1/10


4/14/24, 10:13 AM B_4_Tips

Plots
In [53]: import seaborn as sns
import matplotlib.pyplot as plt

In [55]: sns.pairplot(df)

C:\Users\Admin\anaconda3\Lib\site-packages\seaborn\axisgrid.py:118: UserWarning: T
he figure layout has changed to tight
self._figure.tight_layout(*args, **kwargs)
<seaborn.axisgrid.PairGrid at 0x1389bd5be10>
Out[55]:

Line Plots
In [56]: sns.lineplot(df,x='total_bill',y='tip')
# Tip increases as Totl_bill increases

<Axes: xlabel='total_bill', ylabel='tip'>


Out[56]:

localhost:8888/nbconvert/html/Desktop/DSBDA GROP B/Assignment 4/B_4_Tips.ipynb?download=false 2/10


4/14/24, 10:13 AM B_4_Tips

In [57]: sns.lineplot(df,x='peoples',y='tip')
# Tip increases as no of people increases

<Axes: xlabel='peoples', ylabel='tip'>


Out[57]:

In [58]: sns.lineplot(df,x='peoples',y='tip',hue='time')
# higher tip at lauch time as compared to Dinner

localhost:8888/nbconvert/html/Desktop/DSBDA GROP B/Assignment 4/B_4_Tips.ipynb?download=false 3/10


4/14/24, 10:13 AM B_4_Tips
<Axes: xlabel='peoples', ylabel='tip'>
Out[58]:

Box Plots
In [59]: sns.boxplot(df,x='day',y='total_bill')

<Axes: xlabel='day', ylabel='total_bill'>


Out[59]:

localhost:8888/nbconvert/html/Desktop/DSBDA GROP B/Assignment 4/B_4_Tips.ipynb?download=false 4/10


4/14/24, 10:13 AM B_4_Tips

In [60]: sns.boxplot(df,x='peoples',y='total_bill',hue='day')

<Axes: xlabel='peoples', ylabel='total_bill'>


Out[60]:

In [61]: sns.boxplot(df,x='day',y='total_bill',hue='sex')

<Axes: xlabel='day', ylabel='total_bill'>


Out[61]:

localhost:8888/nbconvert/html/Desktop/DSBDA GROP B/Assignment 4/B_4_Tips.ipynb?download=false 5/10


4/14/24, 10:13 AM B_4_Tips

Histogram
In [62]: sns.histplot(df,x='total_bill',hue='time')

<Axes: xlabel='total_bill', ylabel='Count'>


Out[62]:

In [63]: sns.histplot(df,x='tip',hue='sex')

<Axes: xlabel='tip', ylabel='Count'>


Out[63]:

localhost:8888/nbconvert/html/Desktop/DSBDA GROP B/Assignment 4/B_4_Tips.ipynb?download=false 6/10


4/14/24, 10:13 AM B_4_Tips

In [64]: sns.histplot(df,x='tip',hue='smoker')

<Axes: xlabel='tip', ylabel='Count'>


Out[64]:

Scatter Plots
In [65]: sns.scatterplot(df,x='total_bill',y='tip',hue='time')

localhost:8888/nbconvert/html/Desktop/DSBDA GROP B/Assignment 4/B_4_Tips.ipynb?download=false 7/10


4/14/24, 10:13 AM B_4_Tips
<Axes: xlabel='total_bill', ylabel='tip'>
Out[65]:

In [66]: sns.scatterplot(df,x='total_bill',y='tip',hue='smoker')

<Axes: xlabel='total_bill', ylabel='tip'>


Out[66]:

Violen
localhost:8888/nbconvert/html/Desktop/DSBDA GROP B/Assignment 4/B_4_Tips.ipynb?download=false 8/10
4/14/24, 10:13 AM B_4_Tips

In [67]: sns.violinplot(df,x ='day', y ='tip')

<Axes: xlabel='day', ylabel='tip'>


Out[67]:

In [68]: sns.violinplot(df,x ='time', y ='tip',hue='day')

<Axes: xlabel='time', ylabel='tip'>


Out[68]:

localhost:8888/nbconvert/html/Desktop/DSBDA GROP B/Assignment 4/B_4_Tips.ipynb?download=false 9/10


4/14/24, 10:13 AM B_4_Tips

In [69]: sns.violinplot(df,x ='peoples', y ='total_bill')

<Axes: xlabel='peoples', ylabel='total_bill'>


Out[69]:

In [ ]:

In [ ]:

localhost:8888/nbconvert/html/Desktop/DSBDA GROP B/Assignment 4/B_4_Tips.ipynb?download=false 10/10

You might also like