Pandas - Writing an excel file containing unicode - IllegalCharacterError

后端 未结 7 1353
离开以前
离开以前 2021-02-07 17:05

I have the following code:

import pandas as pd

x = [u\'string with some unicode: \\x16\']
df = pd.DataFrame(x)

If I try to write this datafram

7条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-07 18:08

    The same problem happened to me. I solved it as follows:

    First, install python package xlsxwriter:

    pip install xlsxwriter
    

    Second, replace the default engine 'openpyxl' with 'xlsxwriter':

    df.to_excel("test.xlsx", engine='xlsxwriter')
    

提交回复
热议问题