I can't open a CSV file (i want to open it without pandas) in pycharm
Question:
The following code is provided by my university to open a csv file:
import csv with open("groningenRestaurants.csv") as handler_csv_file: raw_content_file = csv.reader(handler_csv_file) table = list(raw_content_file)
However, when running this the following error occurs:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 1250: : invalid continuation byte
how can i overcome this?
Answers:
As others have suggested, try to specify another encoding than ‘utf-8’, e.g. ‘latin-1’, like this:
with open("groningenRestaurants.csv", encoding='latin-1') as handler_csv_file:
raw_content_file = csv.reader(handler_csv_file)
If you are not able to solve it this way, you could try the ‘ignore’ errors option and see what comes out:
with open("groningenRestaurants.csv", errors='ignore') as handler_csv_file:
raw_content_file = csv.reader(handler_csv_file)
The following code is provided by my university to open a csv file:
import csv with open("groningenRestaurants.csv") as handler_csv_file: raw_content_file = csv.reader(handler_csv_file) table = list(raw_content_file)
However, when running this the following error occurs:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 1250: : invalid continuation byte
how can i overcome this?
As others have suggested, try to specify another encoding than ‘utf-8’, e.g. ‘latin-1’, like this:
with open("groningenRestaurants.csv", encoding='latin-1') as handler_csv_file:
raw_content_file = csv.reader(handler_csv_file)
If you are not able to solve it this way, you could try the ‘ignore’ errors option and see what comes out:
with open("groningenRestaurants.csv", errors='ignore') as handler_csv_file:
raw_content_file = csv.reader(handler_csv_file)