Programming with Python (lab classes)

Stefan Güttel, guettel.com

Content:

  1. Files

Download the file Met_Office_2011_Air_Data.csv from data.gov.uk.

Problem 1. Write a program that reads the file Met_Office_2011_Air_Data.csv and prints:

  • Total cost for all the flights,

  • Total cost per each air carrier, sorted by that cost (i.e., the last carrier will be the one with whom the spending was biggest).

Problem 2. Write a program that inputs a journey finishing point and then reads the file Met_Office_2011_Air_Data.csv and prints total and average cost for all the journeys with that finishing point. The matching has to be case insensitive.

Problem 3. Write a program that reads the file Met_Office_2011_Air_Data.csv and in the directory output creates the files single.csv and return.csv, containing only the data for single and return flights, respectively. It has to copy all the data except the "Ticket Single or Return" column and both files have to be proper CSV files (with headers, and a comma as the column separator).

Use the function os.path.exists to check if the output directory exists, the function os.mkdir to create it, and the function os.path.join to join the directory name with filenames to create the output files' path names.

Problem 4. How many public toilets are there in each of the Australian towns, and how many of them are there in each of the Australian states? Of those towns that have a public toilet, which ones have the longest name and which one has the most toilets (and how many)?

Hint: Write a program that will answer these questions by analyzing the CSV file that can be obtained here (scroll down to Latest CSV Export and choose Explore, Go to resource).