-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.py
65 lines (44 loc) · 1.33 KB
/
code.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# --------------
# Importing header files
import numpy as np
import warnings
warnings.filterwarnings('ignore')
#New record
new_record=[[50, 9, 4, 1, 0, 0, 40, 0]]
#Reading file
data = np.genfromtxt(path, delimiter=",", skip_header=1)
print(data.shape)
#Code starts here
census=np.concatenate((data,new_record),axis=0)
print(census.shape)
age=census[:,[0]]
max_age=np.max(age)
print(max_age)
min_age=np.min(age)
age_mean=np.mean(age)
age_std=np.std(age)
race_0=census[census[:,2]==0,:][:,:]
race_1=census[census[:,2]==1,:][:,:]
race_2=census[census[:,2]==2,:][:,:]
race_3=census[census[:,2]==3,:][:,:]
race_4=census[census[:,2]==4,:][:,:]
len_0=len(race_0)
len_1=len(race_1)
len_2=len(race_2)
len_3=len(race_3)
len_4=len(race_4)
mx_list=[len_0,len_1,len_2,len_3,len_4]
minority_race=mx_list.index(min(mx_list))
print(f"{minority_race}")
senior_citizens=census[census[:,0]>60,:][:,:]
working_hours_sum=np.sum(senior_citizens[:,6])
senior_citizens_len=len(senior_citizens)
avg_working_hours=(working_hours_sum/senior_citizens_len).round(2)
print(working_hours_sum)
print(avg_working_hours)
high=census[census[:,1]>10,:][:,:]
low=census[census[:,1]<=10,:][:,:]
avg_pay_high=np.mean(high[:,7]).round(2)
avg_pay_low=np.mean(low[:,7]).round(2)
print(avg_pay_high)
print(avg_pay_low)