I am trying to convert all csv files of a folder to xlsx and using below code.
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". 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
msg = email.message_from_string(str(arr[1], 'ISO 8859-1')) 使用 'ISO 8859-1' 而不是 'utf-8'
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.