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?

Asked By: Rutger

||

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)
Answered By: Stefan
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.