Question: Using Python 3.6 and write a function,Thanks! Example output: >>> raw_data = parse_data('case_list.csv') >>> print(raw_data) ([[4, 17, 67, 76, 51, 28, 3, 1, 0, 0,
Using Python 3.6 and write a function,Thanks!
Example output:
>>> raw_data = parse_data('case_list.csv') >>> print(raw_data) ([[4, 17, 67, 76, 51, 28, 3, 1, 0, 0, 0, 1], [0, 1, 8, 28, 69, 129, 83, 55, 19, 4, 0, 0], [0, 0, 0, 8, 86, 55, 0, 0, 0, 0, 0, 0], [0, 0, 1, 10, 24, 43, 64, 58, 58, 26, 12, 0], [0, 0, 2, 15, 56, 116, 51, 8, 0, 0, 0, 0]], 1337, 13)
Write a function parse_data(filename) that reads in a series of records from a file, each corresponding to a reported case of flu (from the years 2010-2014), and converts the data into a collection of monthly case counts for each year. The function should return a 3-tuple containing a nested list of monthly case counts for each year. This nested list should be 5 x 12 elements in size (please see below in the example); the number of valid records; and the number of invalid records The data in the file consists of records. Each record consists of four items: year, month (3-character code), age and sex. You will only need to use the first two items (year and month) This is an example of the data in the file case_list.csv year,month,age, sex 2011,APR,29,M 2011,MAR,37,F 2012,MAY,63,M 2012,MXX,63,M Assumptions You can assume that the file is correctly formatted (ie, begins with a header row as in the above example) You can assume that each record is correctly formatted, but your function should only count valid records. A valid record is a record that has valid values for year and month. Valid years are: 2010, 2011, 2012,2013,2014 Valid months are: JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC Invalid records should be ignored
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
