xls 및 csv 모듈과 함께 Python 3.3을 사용하여 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