ABCD
ABCD
ABCD
In [1]:
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
#freqtable
guests_rating = ['Below Average', 'Above Average', 'Above Average', 'Average', 'Above Ave
'Above Average', 'Average', 'Above Average', 'Below Average', 'Poor', 'Excellent', 'Abo
'Average', 'Above Average', 'Above Average', 'Below Average', 'Poor', 'Above Average', '
c=0
rating_unique = set (guests_rating) print (rating_unique)
freqchk=[]
for i in rating_unique:
c = guests_rating.count(i) freqchk.append(c)
freqchk = list(freqchk) print (freqchk)
Out[1]:
0 Excellent 1
1 Poor 2
2 Above Average 9
3 Below Average 3
4 Average 5
localhost:8889/notebooks/ds.ipynb 1/9
7/11/23, 7:43 PM ds - Jupyter Notebook
In [2]:
#bargraph
plt.xlabel("Quality Rating")
plt.ylabel("Frequency")
plt.title("Marada inn quality ratings")
plt.show()
localhost:8889/notebooks/ds.ipynb 2/9
7/11/23, 7:43 PM ds - Jupyter Notebook
In [19]:
#piechart
localhost:8889/notebooks/ds.ipynb 3/9
7/11/23, 7:43 PM ds - Jupyter Notebook
In [4]:
#histogram
data = ['Below Average', 'Above Average', 'Above Average', 'Average', 'Above Average', '
'Above Average', 'Average', 'Above Average', 'Below Average', 'Poor', 'Excellent', 'Abo
'Average', 'Above Average', 'Above Average', 'Below Average', 'Poor', 'Above Average',
seq = [0,1,2,3,4]
fig = plt.figure(figsize = (8, 6)) plt.xlabel("Quality Ratings") plt.ylabel("Frequency")
plt.title("Marada inn quality ratings")
In [5]:
#relativeand%freq
tab['Relative Frequency'] = tab['Frequency'] / tab['Frequency'].sum() tab['Pecent
Frequency'] = tab['Relative Frequency'] * 100
tab
Out[5]:
localhost:8889/notebooks/ds.ipynb 4/9
7/11/23, 7:43 PM ds - Jupyter Notebook
In [7]:
#scatterplot
no_of_interceptions_x = [1, 3, 2, 1, 3]
no_of_points_scored_y = [14, 24, 18, 17, 30]
plt.figure(figsize=(10, 5))
plt.scatter(no_of_interceptions_x, no_of_points_scored_y, color='grey') plt.xlabel("No of
Interceptions")
plt.ylabel("No of Points Scored")
plt.title('No of Interceptions vs No of Points Scored') plt.show()
localhost:8889/notebooks/ds.ipynb 5/9
7/11/23, 7:43 PM ds - Jupyter Notebook
In [10]:
#stackedbargraph
x = ['Colonial', 'Log', 'Split', 'A-Frame'] data_less_250k = [18, 6, 9, 12]
data_more_250k = [12, 14, 16, 3] plt.bar(x,data_less_250k , color='green')
plt.bar(x,data_more_250k, bottom=data_less_250k, color='pink') plt.show()
In [11]:
Out[11]:
#Crosstabulation
localhost:8889/notebooks/ds.ipynb 6/9
7/11/23, 7:43 PM ds - Jupyter Notebook
In [12]:
#sidebyside bar chart
cross_tab_df.T.plot(kind='bar', figsize=(10, 5))
plt.ylim(0, 20)
plt.yticks(range(0, 21, 2)) plt.xticks(rotation=0) plt.xlabel("House Style")
plt.ylabel("Frequency") plt.title('Finger Lake Homes') plt.show()
localhost:8889/notebooks/ds.ipynb 7/9
7/11/23, 7:43 PM ds - Jupyter Notebook
In [18]:
import numpy as np
import matplotlib.pyplot as plt
d=[91,78,93,57,75,52,99,80,97,62,71,69,72,89,66,75,79,75,72,76,104,74,62,68,97,105,77,65
, 62,82,98,101,79,105,79,69,62,73]
# Optional - show all unique values on x-axis. # Matplotlib might hide some of them
plt.gca().set_xticks(unique_values)
localhost:8889/notebooks/ds.ipynb 8/9
7/11/23, 7:43 PM ds - Jupyter Notebook
In [15]:
# Creating histogram
fig, ax = plt.subplots(figsize =(10, 7)) ax.hist(d, bins = [50,60,70,80,90,100,110])
plt.xlabel("parts_Cost") plt.ylabel("Frequency") plt.title("Tune-up parts cost")
# Show plot
plt.show()
In [ ]:
localhost:8889/notebooks/ds.ipynb 9/9