Pandas Unicode Import Export error with to_excel() read_excel()
But why does to_excel() / re_excel() change the original code?
I don't know. I briefly looked at the source of to_excel
from_excel
, but couldn't find any clues.
Setting engine='xlsxwriter'
and leaving encoding
to default seems to do it, i.e.:
import pandas as pddf = pd.DataFrame( {'joe': [['dog'], ['cat'], ['fish'], ['rabbit']], 'ben': [['dog'], ['fish'], ['fish'], ['bear']]})with pd.ExcelWriter ('Input Output Test.xlsx') as writer: df.to_excel(writer, sheet_name='Sheet1', engine='xlsxwriter')dfi = pd.read_excel('Input Output Test.xlsx')assert eval(dfi.iloc[2,1]) == df.iloc[2,1]# True