0

I am reading in an excel file and then spitting out a sheet from that excel file, both using pandas. However, I am getting an error as follows:

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')

I get the following error:

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

The excel file is available here: https://umd.box.com/s/73dqgf8npqquq3icw6w2z8xq73vob3me

1 Answer 1

1

I'm guessing you're using Python 2. Try changing

 df.to_csv('out.csv')

to

 df.to_csv('out.csv', encoding='utf-8')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.