-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecuter.py
More file actions
49 lines (36 loc) · 1.79 KB
/
executer.py
File metadata and controls
49 lines (36 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import pandas as pd
from analyzer import Analyzer
from visualizer import Visualizer
class Executer:
def __init__(self):
file = 'winemag-data-130k-v2.csv'
df = pd.read_csv(file, nrows=20000)
df = df[pd.notnull(df['country'])]
df = df[pd.notnull(df['points'])]
df = df[pd.notnull(df['price'])]
df = df[pd.notnull(df['taster_name'])]
df = df[pd.notnull(df['title'])]
df = df[pd.notnull(df['variety'])]
print('Rows: {}\n'.format(df.shape[0]))
self.df = df
def visualize(self):
visualizer = Visualizer()
data = self.df.groupby(['country'])['points'].mean()
visualizer.create_bar_plot(data.index, data.values, 'Average points per country', 'Country', 'Points')
data = self.df.groupby('variety').agg({'points': 'mean', 'price': 'mean', 'variety': 'size'}).rename(columns={'variety': 'count'})
visualizer.create_scatter_plot(data.index, data['price'], data['points'], data['count'], 'Average points and price per variety', 'Price', 'Points', 'Total')
data = self.df['taster_name'].value_counts()
visualizer.create_pie_chart(data.index, data.values, 'Amount of reviews')
visualizer.show_plots()
def analyze(self):
analyzer = Analyzer()
points = self.df['points'].values
print('Calculations made on points column:')
print('Maximum: {}'.format(analyzer.calculate_maxmimum(points)))
print('Sum: {}'.format(analyzer.calculate_sum(points)))
print('Mean: {}'.format(analyzer.calculate_mean(points)))
print('Variance: {}'.format(analyzer.calculate_variance(points)))
print('Standard Deviation: {}'.format(analyzer.calculate_standard_deviation(points)))
executer = Executer()
executer.analyze()
executer.visualize()