从pandas读取的excel文件中创建csv时出错

时间:2015-09-23 19:02:21

标签: python pandas

我正在读取excel文件,然后使用pandas从该excel文件中吐出一张表。但是,我收到如下错误:

try:
    fao_file = pd.ExcelFile('FAO_Crops_area_harvested_Data.xlsx')
except:
    logging.info('Error reading excel file on FAO data')

df = fao_file.parse('Production_Crops_E_All_Data.csv')
df.to_csv('out.csv')

我收到以下错误:

UnicodeEncodeError: 'ascii' codec can't encode character u'\xf4' in position 1: ordinal not in range(128)

excel文件可在此处获得: https://umd.box.com/s/73dqgf8npqquq3icw6w2z8xq73vob3me

1 个答案:

答案 0 :(得分:1)

我猜你正在使用Python 2.尝试更改

 df.to_csv('out.csv')

 df.to_csv('out.csv', encoding='utf-8')