Python加载sklearn中加载的未知字符

2024-04-26 09:19:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试加载我复制到rtf文件(作为我的培训数据)的电子邮件 我使用sklearn模块和命令加载包含文件的目录:

    sklearn.datasets.load_files
   corpus =  sklearn.datasets.load_files(<path>,shuffle = False)

当我试图打印语料库数据,前6000个左右的字符是\x00\x00\x00\x01Bud1\x00\x00\x10\x00\x00\x00\x08。然后显示实际的消息文本,但文本中间的字符相互交织,如:\cf0\expnd0\kerning0\nHey,\\等。 我想指出的是,有些文本除了英文外,还有德语字符。在

有什么问题吗?在

最佳 好的


Tags: 模块文件数据文本命令目录电子邮件load
1条回答
网友
1楼 · 发布于 2024-04-26 09:19:56

在这个函数的文档中

If you leave encoding equal to None, then the content will be made of bytes instead of Unicode, and you will not be able to use most functions in sklearn.feature_extraction.text.

在不知道文件编码的情况下,您可能想尝试一下

sklearn.databases.load_files(<path>,shuffle = False, encoding='utf-8')

相关问题 更多 >