ExpertData Analysis50 points

Spot the outlier flights

An airline's quality team flags unusual delays using a z-score, so that one bad storm day does not hide inside the average. Data: flights.csv.

  • flight_id, airline, origin, dest, date
  • delay_min: minutes late (negative = early), empty if cancelled
  • cancelled: 1 or 0

Task: the first input line is an airline, the second a number k. Use only its non-cancelled flights. Compute the mean and the population standard deviation (divide by n, not n-1; statistics.pstdev). The z-score of a flight is (delay - mean) / sd. Print Flights: N mean=M sd=S (2 decimals for M and S), then one line FLIGHT_ID DELAY Z (Z signed, 2 decimals) for every flight with abs(z) > k, ordered by abs(z) descending, ties by flight_id. If none is found, or the airline has fewer than 2 flights, or sd is 0, the last line is No outliers; if the airline has no flights print only Flights: 0.

Files your program can read

flights.csv221 lines
flight_id,airline,origin,dest,date,delay_min,cancelled
FL1001,Pacific Jet,LHR,SYD,2025-03-30,1,0
FL1002,Sahara Express,DEL,LHR,2025-03-27,-6,0
FL1003,Sahara Express,GRU,FRA,2025-03-07,26,0
FL1004,Andes Connect,DEL,DXB,2025-03-12,-2,0
FL1005,Andes Connect,NBO,YYZ,2025-03-26,41,0
FL1006,Sahara Express,FRA,DXB,2025-03-26,40,0
FL1007,Sahara Express,SYD,SIN,2025-03-05,12,0
...

Open them by name, for example open("flights.csv").

Sample test

Input

Nordwind
2

Expected output

Flights: 35 mean=35.94 sd=73.75
FL1031 293 +3.49
FL1127 290 +3.44

Your answer is also checked against 5 hidden tests.

Need a hint?

statistics.pstdev is the population version; statistics.stdev would divide by n-1 and give different z-scores.