write hebrew to excel with df.to_csv() and 'utf-8' present weird chars
Asked Answered
R

1

5

I have a dataframe with words in Hebrew. I am using df.to_csv(encoding='utf-8') to write it but the words are not presented good:

enter image description here

When open it in TextEdit, I see the Hebrew properly. I am using Mac with Python3 and Microsoft Excel 16.16. Any ideas how to fix it?

Resurrection answered 14/10, 2018 at 12:57 Comment(9)
The problem is in the software you use to view the file. Make sure the encoding is not set to ASCIIMarietta
@Marietta How to do it with excel 16.16 in Mac? couldn't find itResurrection
Not related to SO: superuser.com/questions/280603/…Marietta
superuser.com/questions/1366665/…Resurrection
I cannot reproduce your problem with your file, since you did not share the file. But in Windows Excel, when you import a csv file, there is an option to choose the source data encoding. Does that not exist in Mac Excel?Delightful
@RonRosenfeld no, and I also couldn't change it in Save AsResurrection
What happens when you select Data/From Text? The text import wizard should open, and that should have an option to specify File Origin, even on the MAC. Note that there is a difference betweein importing and opening a fileDelightful
import using Data->Get External data and choosing UTF-8 workedResurrection
And that was the answer given in the duplicate of your message first posted in superuser.Delightful
B
10

Try:

df.to_csv(file_path, index=False ,encoding = 'utf-8-sig')
Blakeblakelee answered 16/8, 2020 at 11:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.