-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv_analyzer.py
More file actions
52 lines (33 loc) · 1.06 KB
/
Copy pathcsv_analyzer.py
File metadata and controls
52 lines (33 loc) · 1.06 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
50
51
52
import csv
class CSVAnalyzer:
def __init__(self, file_name):
self.file_name = file_name
self.employees = []
def load_data(self):
with open(
self.file_name,
"r",
newline=""
) as file:
reader = csv.DictReader(file)
for row in reader:
self.employees.append(row)
def get_average_salary(self):
total_salary = sum(
int(employee["Salary"])
for employee in self.employees
)
return total_salary / len(self.employees)
def get_department_summary(self):
summary = {}
for employee in self.employees:
department = employee["Department"]
if department not in summary:
summary[department] = 0
summary[department] += 1
return summary
def get_highest_salary(self):
return max(
self.employees,
key=lambda employee: int(employee["Salary"])
)