UnicodeDecodeError: 'utf8' codec can't decode byte 0xa5 in position 0: invalid start byte UnicodeDecodeError: 'utf8' codec can't decode byte 0xa5 in position 0: invalid start byte python python

UnicodeDecodeError: 'utf8' codec can't decode byte 0xa5 in position 0: invalid start byte


I switched this simply by defining a different codec package in the read_csv() command:

encoding = 'unicode_escape'

Eg:

import pandas as pddata = pd.read_csv(filename, encoding= 'unicode_escape')


Try the below code snippet:

with open(path, 'rb') as f:  text = f.read()


The error is because there is some non-ascii character in the dictionary and it can't be encoded/decoded. One simple way to avoid this error is to encode such strings with encode() function as follows (if a is the string with non-ascii character):

a.encode('utf-8').strip()