Number 4??? Please Problem!\" / > ? . Problem 1.pyxl n FlightTirme.csv × L®soltn
ID: 669736 • Letter: N
Question
Number 4??? PleaseProblem!" / > ? . Problem 1.pyxl n FlightTirme.csv × L®soltn.txtx: Time, Departure Delay,Arrival Time,Arrival Delay, Flight Time Flight Date, Carrier, Flight Number, Origin, Destination, Departure 1/1/2015, AA,278, ORD, PHX, 1230,25, 1517,17,167 1/1/2015, AA,1150, ORD, PHX, 2024,19, 2317,22,173 1/1/2015, AA, 1583, ORD, PHX, 1601,76,1900, 85,179 1/1/2015, F9, 1061, ORD, PHX, 0649,-11,1000,10,191 1/1/2015,NK, 167, ORD, PHx, 2112, -3, 2230, 6,78 1/1/201S, UA, 393, ORD, PHX, 2024,1,2318,-3, 174 1/1/2015, US, 2023,ORD, PHX, 1057,2,1342,2, 165 1/1/2015, UA, 725, ORD, PHX, 0906,36, 1205, 37,179 1/1/2015,US, 409, ORD, PHX, 1406,1, 1706,11,180 1/1/2015, US, 424, ORD, PHX,0658, -2,0958,-5,180 1/1/201S, US, 472, ORD, PHX, 2027,22,2317,25,170 1/1/201S,US, 563,ORD, PHx, 1716, 6, 2011,10,175 1/1/2015, US, 602,ORD, PHX, 0459,-1,0751, 3,172 1/2/2015, AA, 278, ORD, PHX,1204,-1,1452,-8,168 1/2/2015, AA, 1150, ORD, PHX, 2005, 0,2317,22, 192 1/2/2015, AA, 1583,ORD, PHX, 1442,-3,1723,-12,161 1/2/2015, AA, 1444, ORD, PHx, 0955, 105,1239, 99,164 1/2/2015, F9, 1061, ORD, PHX, 0747,47,1110, 80,203 1/2/2015, NK, 167, ORD, PHX, 2133,18, 2208,7,35 1/2/2015, UA, 590,ORD, PHX, 2304,161,2313,142,9 1/2/2015, UA, 725, CRD, PHX, 0821,-4, 1147.24,206 1/2/2015,Us, 409,ORD, PEX, 1404,-1.1650,-5, 166 1/2/2015, US, 424,ORD, PEX, 0702,2,0946,+17,164 1/2/2015, US, 472,ORD, PHX, 2015,10,2255,3,160 1/2/2015,0s, 472,ORD, RHX, 2015, 10,22ss, 3.160 1/2/2015, US, 563,ORD, PEX, 1714, 4.4958,-3, 164 1/2/2015,us, 602,ORD, PRXx, 0459,-1,o7s9, 11, 160 1/2/2015, us, 2023, ORD, PHX, 1054, -1,1327,-13.153 1/3/2015, AA, 278 ORD.PEX 1245,40.1522,22,157 1/3/2015,AA, 1150,ORD, PHX, 2133,BB.2216.81, 43 1/3/2015 , , 1583, ORD, PEX, 1530,45, 2804, 29,154 1/3/2025 AA,1444 ORD, PHX 081e .1124/24, 196 1/3/2015. F9.1061,ORD, PRx, 0829,89, 1207.137.218 1444.ORD, BHX,oe1e, 8.4124.24,496 1/3/2015,,167,ORD, PHX 2136, 21, 2220.16,44
Explanation / Answer
This might work here l is the data of the file theme is same just check for the airline and add their flight times.
airlines=[]
count={}
avg={}
for j in range(0,len(l)):
if l[j][1] in airlines:
avg[l[j][1]]=avg[l[j][1]]+l[j][9] //if already we have encountered the airline before we just add
count[l[j][1]]=count[l[j][1]]+1
else:
airlines.append(l[j][1]) //for the first time we have seen the airlines
avg[l[j][1]]=0 //initialising
avg[l[j][1]]=l[i][9]
count[l[j][1]]=0
count[l[j][1]]=count[l[j][1]]+1 //counting number of tmes
for k in range(0,len(avg)):
avg[l[k][1]]=avg[l[k][1]]/count[l[k][1]]
Actual program
file = open('FlightTime.csv', 'r')
i=0
l=[None]*100
for line in file:
m= line.split(",")
m[9]=m[9].rstrip(" ")
m[9]=int(m[9])
l[i]=m
i=i+1
file.close()
f=open('FlightTime.csv','w')
line=""
for j in range(0,i):
if l[j][9]>100:
line=""
for k in range(0,10):
line=line+str(l[j][k])+","
print(line)
f.write(line)
airlines=[]
count={}
avg={}
for j in range(0,len(l)):
if l[j][1] in airlines:
avg[l[j][1]]=avg[l[j][1]]+l[j][9]
else:
avg[l[j][1]]=0
avg[l[j][1]]=l[i][9]
count[l[j][1]]=0
count[l[j][1]]=count[l[j][1]]+1
for k in range(0,len(avg)):
avg[l[k][1]]=avg[l[k][1]]/count[l[k][1]]
f.close()
I have written for some one else
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.