I was trying to make a program that would read a CSV file that I downloaded from the WorldBank about every countries GDP over time. I expected it to be able to first open the file, then read it, and then retrieve the Data. However, a giant error message appeared (so big in fact, I will place a separation between it and the code), and when I tried to solve those errors by searching answers on this website, there would only be another error. Here is the code. Thank you for anyone willing and able to help out.
import csv
from openpyxl import Workbook
wb = Workbook()
with open(r'C:\Users\Miguel\Downloads\API_NY.GDP.PCAP.CD_DS2_en_csv_v2_1429392.zip') as csvfile:
ws = wb.active
ws.title = "Country Analyzer" #title of the program
ws.sheet_properties.tabColor = "FFFFFF" #RGB values
sheet = wb.get_sheet_by_name('API_NY.GDP.PCAP.CD_DS2_en_csv_v2_1429392')
tuple(sheet['A1':'C3'])
Warning (from warnings module):
File "C:\Users\Miguel\AppData\Local\Programs\Python\Python37-32\I'm so tired of this Work.py", line 14
sheet = wb.get_sheet_by_name('API_NY.GDP.PCAP.CD_DS2_en_csv_v2_1429392')
DeprecationWarning: Call to deprecated function get_sheet_by_name (Use wb[sheetname]).
Traceback (most recent call last):
File "C:\Users\Miguel\AppData\Local\Programs\Python\Python37-32\I'm so tired of this Work.py", line 14, in <module>
sheet = wb.get_sheet_by_name('API_NY.GDP.PCAP.CD_DS2_en_csv_v2_1429392')
File "C:\Users\Miguel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\openpyxl\compat\__init__.py", line 38, in new_func1
return func1(*args, **kwargs)
File "C:\Users\Miguel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\openpyxl\workbook\workbook.py", line 247, in get_sheet_by_name
return self[name]
File "C:\Users\Miguel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\openpyxl\workbook\workbook.py", line 273, in __getitem__
raise KeyError("Worksheet {0} does not exist.".format(key))
KeyError: 'Worksheet API_NY.GDP.PCAP.CD_DS2_en_csv_v2_1429392 does not exist.'
Ps- pls don't judge the name of the file