Python给出了读取xlsx的UnicodeEncodeError

时间:2018-02-05 13:30:56

标签: python xlsx

运行此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?

1 个答案:

答案 0 :(得分:0)

尝试使用编码打开excel:

<强> EX

DataFile=pd.read_excel('indata.xlsx', encoding = 'utf8')