pandas special chars converted to weird chars when saving

Viewed 25

I have a series of texts:

s = ["t1" , "t1", "it wasn’t that simple"]

When saving as csv:

s.to_csv("s.csv")

And then open it in excel, the char ' changed to the following:

"it wasn’t that simple"

How can it be fixed?

1 Answers

Use encoding='utf-16'

Ex:

s = ["t1" , "t1", "it wasn’t that simple"]  
s = pd.Series(s)
s.to_csv(filename, encoding='utf-16', index=False)
Related