Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please create four new functions in the starter code based on these instructions. Thank you so much! Update: all the instructions and new functions should

Please create four new functions in the starter code based on these instructions. Thank you so much!

Update: all the instructions and new functions should be working for starter code to make sure the computation part can run

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

The starter code contains a main function, and your job for this homework is to write all the functions that main relies on, described below - Starter code (and file to submit): mbta.py - Also submit: screenshots/downloads of your two plots - Data file to download: mbta data.csv The data in the CSV file comes from the which regularly releases information about ridership, reliability, and travel times on the T. Download the starter code linked above. Add the functions described below. The starter code contains a completed main and will call your functions when you run the program. If your functions all work, running the program will tell you a little about T ridership and create a couple of plots. You are welcome to reuse any code from class, practicum, or the textbook. Implement the function described below. If you comment out everything in the starter code from line 57 on, it will call only this function (and the read_file function already provided). It doesn't print anything, but you'll be able to see if any errors pop up. - Function \#1: riders_per_line - Parameters: 2d list of strings (matches the structure of CSV file), a string for the MBTA line we care about, an int for the column number where line color lives, and an int for the column number where "number of riders" lives. - Returns: a float indicating the average number of riders getting on the given line. - Does: Looks for the given MBTA line in the 2D list. If found, increase the total number of riders. Computes the average number of riders and returns it. Ex. Given the following arguments as described above - a 2d list of strings, MBTA line we want to look at, column number where we can determine MBTA line color, and column number to find "number of riders": [["green","1","2"],["red","5","2"],["green","8","8"]],"green",0,2 The function should return: 5.0 Problem 2 - Riders by Time of Day Implement the function described below. If you comment out everything in the starter code from line 72 on, it will call the four functions written so far. It doesn't print anything, but you'll be able to see if any errors pop up. - Function \#2: split_by_time - Parameters: 2d list of strings (matches the structure of CSV file), a string for the time period we care about, an int for the column number where the time_period column lives - Returns: a 2d list of strings - Does: Filters the original 2d list based on the given time period, returning a smaller 2d list with just the items that match the given time period Ex. Given the following arguments as described above - [ ["green", "time_period_01", "2", "3"], ["red", "time_period_01", "2", "4"], ["green", "time_period_02", "8", "1"], "time_period_01", 1 This function should return: [["green", "time_period_01", "2", "3"], ["red", "time_period_01", "2", "4"]] plement the two functions described below. After you complete this, un-comment the entire starter de, and it should print some info and generate two plots. You are welcome to reuse any code from class, acticum, or the textbook. - Function \#3: plot_ridership - Parameters: A list of ints (\# of riders per line), and a list of strings (labels for the MBTA line names, which are also conveniently matplotlib colors!) - Returns: nothing - Does: generates a bar plot, with both colors and labels taken from the list of strings, and heights taken from the list of ints Given the following arguments... [10,20,10,20],[ "green", "blue", "red", "orange"] ...this function should create a plot that looks something like this (just to give you a general idea; yours can look different, have better/more info, etc., as long as it's clear and informative as always!). - Function \#4: plot_time_ridership - Function \#4: plot_time_ridership - Parameters: 2d list of floats; each sublist is the ridership of all subway lines at a certain time of day, and a 1d list of strings (the line names). - Returns: nothing - Does: Generates a line chart, calling the get_col function to retrieve the data from each of the 4 lines. Labels and colors in the plot are taken from the list of strings. Given the following arguments: [[1,2,2,3],[10,4,8,3],[4,3,5,1]], ["green", "blue", "red", "orange"] ...this function should create a plot similar to the one below by using get_col to retrieve all the green-line data, which is found at the first position in each list ([1,10,4]) and plotting it, and then retrieving all the blue-line data, which is found at the second position in each list ([2,4,3]) and plotting it, etc. Sample plot based on the arguments above (just to give you a general idea; yours can look different, have better/more info, etc., as long as it's clear and informative as always!). mbta_data mbta_data

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Building The Data Warehouse

Authors: W. H. Inmon

4th Edition

0764599445, 978-0764599446

More Books

Students also viewed these Databases questions

Question

Methods of Delivery Guidelines for

Answered: 1 week ago