strange char when use Python to convert from excel .xlsx to csv file

Viewed 26

i used this to line of code to convert excel file with xlsx extension to csv file but when i have arabic char in excel file i got strange char like

شيم لالنهضه للاستثمار ذªØ«Ù…ار Ø

data_xls = pd.read_excel(newFilename +'.xlsx' , dtype=str , index_col=None)

data_xls.to_csv('CSV ' +newFilename+'.csv', encoding='UTF-8' , index=False , header=True)

any help please ?

1 Answers

I have a solution and I did it with a small change in my code. I replaced encode='utf-8' with encode='utf-8-sig' and it works for me.

My new code:

data_xls = pd.read_excel(excelfilename+'.xlsx' , dtype=str , index_col=None)
data_xls.to_csv(newFilename+'.csv', encoding='utf-8-sig' , index=False , header=True)  
Related