import seaborn as sns
Learned about Seaborn library, a Python data visualization library based on matplotlib. It helps to draw statistical graphics.
import numpy as np
Learned about NumPy which is a package used for scientific computing in Python. It provides all sorts of shape manipulation, sorting, selecting, I/O, discrete Fourier transforms, basic linear algebra, basic statistical operations, random simulation, and much more.
Note- NumPy doesn’t provide calcuations of mode as mode is just counting of occurences while NumPy is used for mathematical calculations.
import matplotlib.pyplot as plt
Learned that matplotlib is a comprehensive library for creating static, animated, and interactive visualizations in Python.
import statistics
Statistics is imported as it is used to calculate the mode for a given data.
#mean, median, mode
df=sns.load_dataset('tips')
In order to load any data set seaborn library is used
If no parameter is given it displays the first five rows
df.head()
index,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.5,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
.head function returns first 5 rows if no parameter is given to it
calculate the mean of total bills
np.mean(df['total_bill'])
19.78594262295082
calculate the median of total bills
np.median(df['total_bill'])
17.795
calculate mode using statics
statistics.mode(df['total_bill'])
13.42
NumPy is only involved in numeric calculations and doesn’t count frequencies of occurrences so we can’t use NumPy