-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaiplanetype.py
42 lines (29 loc) · 862 Bytes
/
aiplanetype.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 csv
from operator import itemgetter
ifile=open('crash.csv','r')
reader=csv.DictReader(ifile)
default=0
i=0
total=0
dictModel={}
dictModelno={}
for row in reader:
try:
if row['Type'] in dictModel:
dictModel[row['Type']]+=int(row['Fatalities'])/int(row['Aboard']);
dictModelno[row['Type']]+=1
else:
dictModel[row['Type']]=int(row['Fatalities'])/int(row['Aboard']);
dictModelno[row['Type']]=1
total=total+1
except Exception as e:
print(e)
default+=1
pass
for key,value in dictModel.items():
dictModel[key]=dictModel[key]/dictModelno[key];
for key,value in sorted(dictModel.items(),key=itemgetter(1),reverse=False)[:50]:
print('key is '+str(key)+' value is '+str(value)+'no of timmes crashed is '+str(dictModelno[key]))
print('default value is '+str(default))
print('total value is '+str(total))
ifile.close()