[英]'utf-8' codec can't decode byte 0x92 in position 11: invalid start byte
I am trying to convert all csv files of a folder to xlsx and using below code.我正在尝试将文件夹的所有 csv 文件转换为 xlsx 并使用以下代码。
import glob
import csv
import pandas as pd
files = glob.glob('D:\cf111\*.csv')
for k in files:
df = pd.read_csv(k)
df.to_excel("abc.xlsx")
The code is generating the below error.该代码正在生成以下错误。
utf-8' codec can't decode byte 0x92 in position 11: invalid start byte
I cant sort out, how to resolve this error.我无法理清,如何解决此错误。
The problem might because there are contents in the csv that do not support encoding="utf-8".问题可能是因为 csv 中有不支持 encoding="utf-8" 的内容。 you can try using other encoding though.
您可以尝试使用其他编码。
code example:代码示例:
import glob
import csv
import pandas as pd
files = glob.glob('D:\cf111\*.csv')
for k in files:
df = pd.read_csv(k, encoding='ISO 8859-1')
df.to_excel("abc.xlsx")
document reference: https://docs.python.org/3/library/codecs.html#standard-encodings文档参考: https : //docs.python.org/3/library/codecs.html#standard-encodings
msg = email.message_from_string(str(arr[1], 'ISO 8859-1')) 使用 'ISO 8859-1' 而不是 'utf-8'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.