0% found this document useful (0 votes)
8 views3 pages

Part B - Program 2

This document discusses visualizing data from a tips database using Python libraries like Pandas, Matplotlib and Seaborn. It loads the tips data, then creates scatter plots, line charts, bar charts and histograms to visualize relationships between variables like tips, total bill amounts and day of the week.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Part B - Program 2

This document discusses visualizing data from a tips database using Python libraries like Pandas, Matplotlib and Seaborn. It loads the tips data, then creates scatter plots, line charts, bar charts and histograms to visualize relationships between variables like tips, total bill amounts and day of the week.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

12/17/23, 1:03 PM Part B - Program 2 - Jupyter Notebook

2. Data visualization with using python (Pandas,


matplotlib, Seaborn) Tips database(tips.csv) is the
record of the tip given by the customers in a
restaurant for two and a half months in the early
1990s. It contains 6 columns such as total_bill,
tip,sex, smoker, day, time, size.
In [1]: import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

• Reading the database and display the top 10 rows (using


pandas)

In [2]: df=pd.read_csv("tips.csv")

In [3]: df.head(10)

Out[3]:
Payer
total_bill tip sex smoker day time size price_per_person
Name

Christy
0 16.99 1.01 Female No Sun Dinner 2 8.49 356032
Cunningham

Douglas
1 10.34 1.66 Male No Sun Dinner 3 3.45 447807
Tucker

Travis
2 21.01 3.50 Male No Sun Dinner 3 7.00 601181
Walters

Nathaniel
3 23.68 3.31 Male No Sun Dinner 2 11.84 467613
Harris

Tonya
4 24.59 3.61 Female No Sun Dinner 4 6.15 483273
Carter

5 25.29 4.71 Male No Sun Dinner 4 6.32 Erik Smith 21314

Kristopher
6 8.77 2.00 Male No Sun Dinner 2 4.38 222372
Johnson

7 26.88 3.12 Male No Sun Dinner 4 6.72 Robert Buck 351478

Joseph
8 15.04 1.96 Male No Sun Dinner 2 7.52 352286
Mcdonald

Jerome
9 14.78 3.23 Male No Sun Dinner 2 7.39 353212
Abbott

localhost:8888/notebooks/Part B - Program 2.ipynb 1/3


12/17/23, 1:03 PM Part B - Program 2 - Jupyter Notebook

• Scatter Plot (day vs tip)

In [4]: plt.scatter(df["day"],df["tip"])
plt.xlabel("Day")
plt.ylabel("Tip")
plt.show()

• Line Chart (day against tip)

In [5]: plt.plot(df["day"],df["tip"])
plt.xlabel("Day")
plt.ylabel("Tip")
plt.show()

localhost:8888/notebooks/Part B - Program 2.ipynb 2/3


12/17/23, 1:03 PM Part B - Program 2 - Jupyter Notebook

• Bar chart with day against tip

In [6]: plt.bar(df["day"],df["tip"])
plt.xlabel("Day")
plt.ylabel("Tip")
plt.show()

• Histogram of total_bills

In [7]: plt.hist(df["total_bill"])
plt.xlabel("Total bill")
plt.ylabel("Frequency")
plt.show()

localhost:8888/notebooks/Part B - Program 2.ipynb 3/3

You might also like