简体   繁体   中英

Encoding and decoding with utf-8 returns UnicodeError

I am both enconding and decoding with utf-8 but still I get a UnicodeError.

import pandas as pd
df.to_csv('myfile.csv', index=False, encoding='utf-8')

Then, in another.py, same project

import pandas as pd
with open(file, 'r') as f:
    csv = pd.read_csv(f, encoding='utf-8')

The error is: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 51956: character maps to <undefined> This is not the first time I get this issue.

Ok, found it. Makes a lot of sense now.

with open(file, 'r', encoding='utf-8') as f:
    csv = pd.read_csv(f)

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