-
Notifications
You must be signed in to change notification settings - Fork 0
/
question1.py
42 lines (39 loc) · 1.09 KB
/
question1.py
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
import pandas as pd
import numpy as np
# data = {}
# data['id'] = [1,2,3,4,5,6,7]
# data['Name'] = ['John','Mike','Sally','Jane','Joe','Dan','Phil']
# data['Salary'] = [300,200,550,500,600,600,550]
# data['manager_id'] = [3,3,4,7,7,3,'NULL']
# df = pd.DataFrame(data)
#without using pandas dataframe
#question 1a
id_ = [1,2,3,4,5,6,7]
Name = ['John','Mike','Sally','Jane','Joe','Dan','Phil']
Salary = [300,200,550,500,600,600,550]
manager_id = [3,3,4,7,7,3,'NULL']
higher_salary = []
for index,each in enumerate(id_):
#data cleaning
if type(manager_id[index]) != int:
continue
if Salary[manager_id[index]-1] < Salary[index]:
higher_salary.append(Name[index])
print(higher_salary)
#output ['Sally', 'Joe', 'Dan']
#question 1b
not_managing = []
for index,each in enumerate(id_):
if each not in manager_id:
not_managing.append(index)
print(not_managing)
Salary_nm = []
Name_nm = []
for index in not_managing:
Salary_nm.append(Salary[index])
Name_nm.append(Name[index])
print(Name_nm)
print(np.average(Salary_nm))
#output
#['John', 'Mike', 'Joe', 'Dan']
#425.0