我使用Python 3.3与xlrd和csv模块将xls文件转换为csv。这是我的代码:使用xlrd在Python 3中将xls转换为csv
import xlrd
import csv
def csv_from_excel():
wb = xlrd.open_workbook('MySpreadsheet.xls')
sh = wb.sheet_by_name('Sheet1')
your_csv_file = open('test_output.csv', 'wb')
wr = csv.writer(your_csv_file, quoting=csv.QUOTE_ALL)
for rownum in range(sh.nrows):
wr.writerow(sh.row_values(rownum))
your_csv_file.close()
有了,我收到此错误:TypeError: 'str' does not support the buffer interface
我试图改变编码,取而代之的是这个循环中的行:
wr.writerow(bytes(sh.row_values(rownum),'UTF-8'))
,但我得到此错误:TypeError: encoding or errors without a string argument
任何人都知道可能会出错?
甚至更短:'df = pd.read_excel(...)' – user2146414