DATA 200 Spring 2020 Homework 4
Due Fe
uary 28, 2019 at 11:59pm
Note: Please only use standard python and li
aries covered in class lectures (os & glob).
Other Python li
aries such as pandas, numpy are *not* allowed in your work.
1. This exercise is about consuming airline data in csv format and derive results from the
data. Write Python code to read and parse airline data csv files in a directory that is
provided in the archived file (airline_data.zip). The files are stored in a directory named
“data”. Each csv file contains a header row with column names and airline flight data for
a given day. In particular, the 5th column contains the airline information for the flights:
YEAR,MONTH,DAY,DAY_OF_WEEK,AIRLINE,FLIGHT_NUMBER,………
2015,2,1,7,AA,2400,N3JKAA,……
2015,2,1,7,AS,98,N794AS,……
2015,2,1,7,AA,258,N3FEAA,……
.
.
.
Process all the csv files and tally up the total number of flights by airline and sort them in
descending order and write the results with a header row (Airline, # Flights) to a csv file
(flights_by_airline.csv). Append the results with the total sum of all airline flights. This
esult file should look like the following (the values shown may not be the actual ones):
Airline,# Flights
WN,93215
DL,45912
.
.
.
Total,438382
Here are additional requirements for your work:
i. Your code should be able to handle any number of csv files with the above specified
format present in the data subdirectory.
ii. You must define a generator function to read and parse an input (csv) file. This
function will “yield” parsed data from the input file line by line. Use this function to
process all the input csv files.
XXXXXXXXXXpoints)
2. Starting with the list [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], use map and filter functions
only (no list comprehension or for loops) to create the following iterables (lists):
a. [5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
. [1, 3, 5, 7, 9]
c. [1, 9, 81, 729, 6561]
d. [0, 3, 4, 9, 8, 15, 12, 21, 16, 27]
e. [1, 3, 10, 14, 18]
(10 points)