Skip to content Skip to sidebar Skip to footer

Unicodedecodeerror: 'utf-8' Codec Can't Decode Byte 0xa0 In Position 8

I am trying to read a CSV using pd.read_csv, but I get an error: UnicodeDecodeError Traceback (most recent call last) pandas_libs\parsers.pyx in pandas.

Solution 1:

The data you posted works fine for me, but it's several degrees removed from your source. Specifying an encoding when opening the file may fix the problem. You can do this a couple of ways: use the codecs package to open the file and let that decide the encoding, or specify the encoding in csv_read()

import codecs

doc = codecs.open('document','rU','UTF-16') #openfor reading with "universal" type set

df = pandas.read_csv(doc, sep=',')

You also might want to sanitize your column names, as spaces and decimals can cause problems in referencing.

df.columns = df.columns.str.strip().str.lower().str.replace(' ', '_').str.replace('(', '').str.replace(')', '').str.replace('.', '')

Post a Comment for "Unicodedecodeerror: 'utf-8' Codec Can't Decode Byte 0xa0 In Position 8"