Import the CSV module and read the file colleges.csv Process the data from the file for the following: Store the date column in a variable so you can adjust the formatting to be MM/DD/YYYY or YYYY Use the cases_2021 column as the value to decide which sentence option to display Use the county column to determine which school is in Los Angeles county
- Import the CSV module and read the file colleges.csv
- Process the data from the file for the following:
- Store the date column in a variable so you can adjust the formatting to be MM/DD/YYYY or YYYY
- Use the cases_2021 column as the value to decide which sentence option to display
- Use the county column to determine which school is in Los Angeles county
- If the school is in Los Angeles county, output the sentence one of the following example sentences based on the available data as a single string:
- As of MM/DD/YYYY, COLLEGE NAME reported YY cases of COVID-19 in YYYY.
- As of MM/DD/YYYY, COLLEGE NAME reported no cases of COVID-19 in YYYY.
- The sentence in the print() statement should be a single string statement, no commas seperating values
- Some values in the CSV may be modified from the original to ensure you are correctly parsing the data as requested.
colleges.csv
date,state,county,city,ipeds_id,college,cases,cases_2021,notes
2021-05-26,California,Orange,Fullerton,110565,"California State University, Fullerton",45,23,
2021-05-26,California,Los Angeles,Long Beach,110583,"California State University, Long Beach",163,64,
2021-05-26,California,Los Angeles,Los Angeles,110592,"California State University, Los Angeles",199,,
2021-05-26,California,Monterey,Marina,409698,"California State University, Monterey Bay",18,8,
2021-05-26,California,Los Angeles,Los Angeles,110608,"California State University, Northridge",149,55,
2021-05-26,California,Sacramento,Sacramento,110617,"California State University, Sacramento",148,46,
2021-05-26,California,San Bernardino,San Bernardino,110510,"California State University, San Bernardino",43,15,
2021-05-26,California,San Diego,San Marcos,366711,"California State University, San Marcos",118,37,
2021-05-26,California,Stanislaus,Turlock,110495,"California State University, Stanislaus",39,19,
2021-05-26,California,Orange,Orange,111948,Chapman University,377,225,
2020-12-31,California,Los Angeles,Claremont,112260,Claremont McKenna College,0,,
2021-05-26,California,Orange,Irvine,112075,Concordia University Irvine,82,59,
2021-05-26,California,Orange,Cypress,113236,Cypress College,20,1,
2021-05-26,California,Marin,San Rafael,113698,Dominican University of California,32,24,
2021-05-26,California,Los Angeles,Torrance,113980,El Camino Community College,35,16,
Output:
As of 05/26/2021, California State University, Long Beach reported 163 cases of COVID-19 in 2021.
As of 05/26/2021, California State University, Los Angeles reported no cases of COVID-19 in 2021.
As of 05/26/2021, California State University, Northridge reported 149 cases of COVID-19 in 2021.
Code attempt:
import csv
def main():
with open("colleges.csv", "r") as csv_file:
csv_reader = csv.reader(csv_file)
date = ("date".format('%m/%d/%Y')
cases_2021 = "cases"
county = "Los Angeles"
college = "college"
yyyy = "2021"
if cases reported = yy
return yy
else:
return reported no cases
for row in csv_reader:
print("As of" + date, college, "reported of covid19 in " + yyyy)
# DO NOT MODIFY BELOW
if __name__ == "__main__":
# Call Main Program
main()
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images
How do you change the date from mm/dd/yyyy to dd/mm/yyyy?