Search code examples
pandasmacosdataframecsvexport-to-csv

pandas special chars converted to weird chars when saving


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?


Solution

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