Pandas - Writing an excel file containing unicode - IllegalCharacterError

后端 未结 7 1343
离开以前
离开以前 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 17:46

    Use this to remove any error that you might be getting. You can save to excel post this.

    df = df.applymap(lambda x: x.encode('unicode_escape').
                     decode('utf-8') if isinstance(x, str) else x)
    

提交回复
热议问题