我有一个带有特殊字符 [˛] 作为分隔符的文本文件。我在 read_csv 命令中复制粘贴了这个特殊字符作为分隔符,但出现以下错误:
ParserWarning: Falling back to the 'python' engine because the
separator encoded in utf-8 is > 1 char long, and the 'c' engine does
not support such separators; you can avoid this warning by specifying
engine='python'.
"""Entry point for launching an IPython kernel.
知道如何在读取文本文件时使用特殊字符吗?
您只会收到警告和解决方案,删除它非常简单 - 添加engine='python'
.
指定解析器引擎 http://pandas.pydata.org/pandas-docs/stable/io.html#specifying-the-parser-engine:
在底层,pandas 使用了一个快速高效的解析器,它的实现是C
以及目前功能更完整的 python 实现。在可能的情况下 pandas 使用 C 解析器(指定为engine='c'
),但如果指定了 C 不支持的选项,则可能会回退到 python。目前,C 语言不支持的选项包括:
-
sep 不是单个字符(例如正则表达式分隔符)
- 跳页脚
- sep=无 delim_whitespace=False
指定上述任何选项都会产生 ParserWarning,除非使用显式选择 python 引擎engine='python'
.
import pandas as pd
from pandas.compat import StringIO
temp=u"""a˛b˛c
1˛3˛5
7˛8˛1
"""
#after testing replace 'StringIO(temp)' to 'filename.csv'
df = pd.read_csv(StringIO(temp), sep="˛", engine='python')
print (df)
a b c
0 1 3 5
1 7 8 1
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)