运行此Python代码时:
import pandas as pd
from pandas import ExcelWriter
from pandas import ExcelFile
import unicodedata
import codecs
DataFile=pd.read_excel('indata.xlsx')#,dtype={'text': unicode})
for Rownumber in range (0,7):# 2? til 23761?
print('rownumber: ', Rownumber)
ColumnF=str((DataFile.iloc[Rownumber,5]))
print('ColumnF: ', ColumnF)
print('EOF')
我收到以下错误:
('rownumber: ', 0)
Traceback (most recent call last):
File "example.py", line 13, in <module>
ColumnF=str((DataFile.iloc[Rownumber,5]))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe6' in position 11: ordinal not in range(128)
任何想法如何让Python在xlsx中读取包含非ascii utf8 caharacters的xlsx?
答案 0 :(得分:0)
尝试使用编码打开excel:
<强> EX 强>:
DataFile=pd.read_excel('indata.xlsx', encoding = 'utf8')