I want to export a pandas dataframe to Excel, but I face several issue:
1/ I have a column beginning with "=", which of course is read like a formula with excel. To avoid that, for my datframe column I did that:
df['mc'] = "'" + df['mc']
But when I do that Excel read it as a text and don't delete the "'" as it should do...
For example:
d = p.DataFrame({'test1': ["=1+2+3"], 'test2': ["'=1+2+3"]})
d.to_excel('test3.xlsx')
First column is written "6". Second is written "'=1+2+3" What I want is "=1+2+3"
2/ My text columns are French ones with special character like "oe" (like in oeuf = egg, called "le e dans l'o"), which are not exported... I encoded the export like this:
df.to_excel("test1.xlsx", encoding='utf8')
But it doesn't change anything. Do you know how I should do it? Thanks,
.apply(lambda x: "'"+x if x[0] == "=" else x)to only apply to strings with equals...