使用python错误信息将excel文件转换为csv

我正在使用PYTHON将excel(xlsx)文件转换为CSV,我收到以下错误消息。

代码:import xlrd import csv

with xlrd.open_workbook('a_file.xlsx') as wb: sh = wb.sheet_by_index(0) # or wb.sheet_by_name('name_of_the_sheet_here') with open('a_file.csv', 'wb') as f: c = csv.writer(f) for r in range(sh.nrows): c.writerow(sh.row_values(r)) 

在c.writerow(sh.row_values(r))中,第9行的文件“C:\ Python27 \ Scripts \ 1.py”UnicodeEncodeError:'ascii'编解码器无法编码字符u'\ xbd'在位置4:序号不在范围内(128)

任何解决错误的光?

 import pandas as pd data_xls = pd.read_excel('a_file.xls', 'Sheet1', index_col=None) data_xls.to_csv('a_file.csv', encoding='utf-8') 

你可以很容易地使用pandas