简体   繁体   中英

Is there a way to encode a csv file to UTF-8 in pandas?

My code: data = pd.read_csv('Downloads/samplefile.csv',low_memory=False, encoding='utf-8')

I receive the error: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd1 in position 258663: invalid continuation byte

Any help is appreciated.

Your data file might NOT be encoded in UTF-8, because the character 0xd1 is Ñ in the encoding ISO8859-1.

So, use the line below:

data = pd.read_csv('Downloads/samplefile.csv',low_memory=False, encoding='iso8859-1')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM