【问题标题】:reading Excel file getting unicodes读取 Excel 文件获取 unicodes
【发布时间】:2022-01-14 02:02:27
【问题描述】:

我正在用 pandas 读取一个 excel 文件。

当我在 microsoft excel 中打开文件时,我得到了这样的输出

当我在 libre office 中看到这个文件时,我得到了这样的输出,

所以在阅读 excel 文件时,我执行了以下代码,但我无法摆脱 x000d

df = pd.read_excel('file.xlsx')
df = df.replace(r'\n',' ', regex=True)
df = df.replace(r'[^\x00-\x7F]+',  '', regex=True)

整个文件中还可以有更多这样的 unicode。 上面的代码替换了每个单元格中的所有新行。

【问题讨论】:

  • x000d 是回车符,而不是换行符 \n。您是否尝试过简单地显式替换特定字符而不使用正则表达式?

标签: python excel pandas


【解决方案1】:

目前我只能通过找到这些类型的 unicode 然后替换它们来解决这个问题。

df.replace({r"_x([0-9a-fA-F]{4})_": ""}, regex=True)

如果有人有更好的主意,请告诉我。

【讨论】:

    猜你喜欢
    • 2015-08-18
    • 1970-01-01
    • 2017-03-04
    • 1970-01-01
    • 2014-10-13
    • 2010-09-06
    相关资源
    最近更新 更多