Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas: UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 0-1: invalid continuation byte

community. I want to open a CSV using pandas and perform analysis on it. Please, help as I am not able to open the CSV itself. I tried opening it with UTF-8, Latin-1, and ISO-8859-1 encoding. It didn't work. CODE:

csv_file3='COVID-19-geographic-disbtribution-worldwide.csv'
with open(csv_file3,'rt')as f:
    data = csv.reader(f)
    j=0
    for row in data:
         j+=1

ERROR:

Traceback (most recent call last):
  File "analysisofcases.py", line 87, in <module>
    for row in data:
  File "/usr/lib/python3.6/codecs.py", line 321, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 15-16: invalid continuation byte

This is the CSV that I want to open. This is my code and the error when I ran the code.** Please check and see what the problem is**

like image 886
Sezal Chug Avatar asked Jun 03 '26 17:06

Sezal Chug


1 Answers

Try this,check this standard encodings as well.

data = pd.read_csv("COVID-19-geographic-disbtribution-worldwide.csv", encoding = 'unicode_escape', engine ='python')
like image 90
Rajith Thennakoon Avatar answered Jun 06 '26 07:06

Rajith Thennakoon