|
| 1 | +# -------------- |
| 2 | +# Importing header files |
| 3 | +import numpy as np |
| 4 | +import warnings |
| 5 | + |
| 6 | +warnings.filterwarnings('ignore') |
| 7 | + |
| 8 | +#New record |
| 9 | +new_record=[[50, 9, 4, 1, 0, 0, 40, 0]] |
| 10 | + |
| 11 | +#Reading file |
| 12 | +data = np.genfromtxt(path, delimiter=",", skip_header=1) |
| 13 | +print(data.shape) |
| 14 | + |
| 15 | + |
| 16 | +#Code starts here |
| 17 | +census=np.concatenate((data,new_record),axis=0) |
| 18 | +print(census.shape) |
| 19 | +age=census[:,[0]] |
| 20 | + |
| 21 | +max_age=np.max(age) |
| 22 | +print(max_age) |
| 23 | +min_age=np.min(age) |
| 24 | +age_mean=np.mean(age) |
| 25 | +age_std=np.std(age) |
| 26 | + |
| 27 | +race_0=census[census[:,2]==0,:][:,:] |
| 28 | +race_1=census[census[:,2]==1,:][:,:] |
| 29 | +race_2=census[census[:,2]==2,:][:,:] |
| 30 | +race_3=census[census[:,2]==3,:][:,:] |
| 31 | +race_4=census[census[:,2]==4,:][:,:] |
| 32 | + |
| 33 | +len_0=len(race_0) |
| 34 | +len_1=len(race_1) |
| 35 | +len_2=len(race_2) |
| 36 | +len_3=len(race_3) |
| 37 | +len_4=len(race_4) |
| 38 | + |
| 39 | +mx_list=[len_0,len_1,len_2,len_3,len_4] |
| 40 | +minority_race=mx_list.index(min(mx_list)) |
| 41 | +print(f"{minority_race}") |
| 42 | + |
| 43 | +senior_citizens=census[census[:,0]>60,:][:,:] |
| 44 | +working_hours_sum=np.sum(senior_citizens[:,6]) |
| 45 | + |
| 46 | +senior_citizens_len=len(senior_citizens) |
| 47 | +avg_working_hours=(working_hours_sum/senior_citizens_len).round(2) |
| 48 | + |
| 49 | +print(working_hours_sum) |
| 50 | +print(avg_working_hours) |
| 51 | + |
| 52 | +high=census[census[:,1]>10,:][:,:] |
| 53 | +low=census[census[:,1]<=10,:][:,:] |
| 54 | + |
| 55 | +avg_pay_high=np.mean(high[:,7]).round(2) |
| 56 | +avg_pay_low=np.mean(low[:,7]).round(2) |
| 57 | + |
| 58 | +print(avg_pay_high) |
| 59 | +print(avg_pay_low) |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | + |
0 commit comments