有没有办法在 pandas 中将 csv 文件编码为 UTF-8?

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

我的代码:data = pd.read_csv('Downloads/samplefile.csv',low_memory=False, encoding='utf-8')

我收到错误:UnicodeDecodeError:'utf-8'编解码器无法解码位置 258663 中的字节 0xd1:连续字节无效

感谢任何帮助。

您的数据文件可能不是 以 UTF-8 编码,因为字符 0xd1 在编码 ISO8859-1 中是 Ñ

因此,请使用以下行:

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