1

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,

1
  • You could .apply(lambda x: "'"+x if x[0] == "=" else x) to only apply to strings with equals... Commented Nov 29, 2021 at 9:37

1 Answer 1

2

Try

df.to_excel("test1.xlsx",encoding='utf-8-sig')
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.