Python - Why does this code not execute properly? Code: import csv import matplotlib.pyplot as plt def read_csv(iso_code): with open('owid-covid-data.csv', encoding='utf-8-sig', mode='r') as csvFormat: csvFile = csv.reader(csvFormat) day = [] cases = [] line = 1 for row in csvFile: line += 1 if row[0] == iso_code: if line > 1: day.append(int(row[3])) cases.append(int(row[4])) return day, cases def data_charts(data1, data2, type): fig = plt.figure() ax = fig.add_subplot(1, 1, 1) if type == 'bar': ax.bar(data1, data2) elif type == 'line': ax.plot(data1, data2) elif type == 'scatter': ax.scatter(data1, data2, s=2, c='blue', marker='+') ax.set_xlabel('Day') ax.set_ylabel('New Cases') ax.set_title('New cases by day for', type) ax.grid() plt.show() iso_code = input('Enter a country ISO code like KOR, MEX, USA, CAN, NZL: ') plotData = input('Enter chart type line, bar, or scatter: ') x, y = read_csv(iso_code) data_charts(x, y, plotData) Example File: iso_code,continent,location,date,total_cases,new_cases AFG,Asia,Afghanistan,2/24/2020,1,1 AFG,Asia,Afghanistan,2/25/2020,1,0 AFG,Asia,Afghanistan,2/26/2020,1,0 AFG,Asia,Afghanistan,2/27/2020,1,0 AFG,Asia,Afghanistan,2/28/2020,1,0 AFG,Asia,Afghanistan,2/29/2020,1,0 AFG,Asia,Afghanistan,3/1/2020,1,0 AFG,Asia,Afghanistan,3/2/2020,1,0 AFG,Asia,Afghanistan,3/3/2020,2,1 AFG,Asia,Afghanistan,3/4/2020,4,2 AFG,Asia,Afghanistan,3/5/2020,4,0 AFG,Asia,Afghanistan,3/6/2020,4,0 AFG,Asia,Afghanistan,3/7/2020,4,0 AFG,Asia,Afghanistan,3/8/2020,5,1 AFG,Asia,Afghanistan,3/9/2020,7,2 AFG,Asia,Afghanistan,3/10/2020,8,1 AFG,Asia,Afghanistan,3/11/2020,11,3 AFG,Asia,Afghanistan,3/12/2020,12,1 AFG,Asia,Afghanistan,3/13/2020,13,1 AFG,Asia,Afghanistan,3/14/2020,15,2

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Python - Why does this code not execute properly?

Code:

import csv import matplotlib.pyplot as plt def read_csv(iso_code): with open('owid-covid-data.csv', encoding='utf-8-sig', mode='r') as csvFormat: csvFile = csv.reader(csvFormat) day = [] cases = [] line = 1 for row in csvFile: line += 1 if row[0] == iso_code: if line > 1: day.append(int(row[3])) cases.append(int(row[4])) return day, cases def data_charts(data1, data2, type): fig = plt.figure() ax = fig.add_subplot(1, 1, 1) if type == 'bar': ax.bar(data1, data2) elif type == 'line': ax.plot(data1, data2) elif type == 'scatter': ax.scatter(data1, data2, s=2, c='blue', marker='+') ax.set_xlabel('Day') ax.set_ylabel('New Cases') ax.set_title('New cases by day for', type) ax.grid() plt.show() iso_code = input('Enter a country ISO code like KOR, MEX, USA, CAN, NZL: ') plotData = input('Enter chart type line, bar, or scatter: ') x, y = read_csv(iso_code) data_charts(x, y, plotData)

Example File:

iso_code,continent,location,date,total_cases,new_cases AFG,Asia,Afghanistan,2/24/2020,1,1 AFG,Asia,Afghanistan,2/25/2020,1,0 AFG,Asia,Afghanistan,2/26/2020,1,0 AFG,Asia,Afghanistan,2/27/2020,1,0 AFG,Asia,Afghanistan,2/28/2020,1,0 AFG,Asia,Afghanistan,2/29/2020,1,0 AFG,Asia,Afghanistan,3/1/2020,1,0 AFG,Asia,Afghanistan,3/2/2020,1,0 AFG,Asia,Afghanistan,3/3/2020,2,1 AFG,Asia,Afghanistan,3/4/2020,4,2 AFG,Asia,Afghanistan,3/5/2020,4,0 AFG,Asia,Afghanistan,3/6/2020,4,0 AFG,Asia,Afghanistan,3/7/2020,4,0 AFG,Asia,Afghanistan,3/8/2020,5,1 AFG,Asia,Afghanistan,3/9/2020,7,2 AFG,Asia,Afghanistan,3/10/2020,8,1 AFG,Asia,Afghanistan,3/11/2020,11,3 AFG,Asia,Afghanistan,3/12/2020,12,1 AFG,Asia,Afghanistan,3/13/2020,13,1 AFG,Asia,Afghanistan,3/14/2020,15,2

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY