Python 3.x python使用特殊字符作为分隔符
我有一个文本文件,其中有一个特殊字符[˛]作为分隔符。我在read_csv命令中复制粘贴了此特殊字符作为分隔符,出现以下错误:Python 3.x python使用特殊字符作为分隔符,python-3.x,csv,pandas,Python 3.x,Csv,Pandas,我有一个文本文件,其中有一个特殊字符[˛]作为分隔符。我在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 w
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'
:
在后台,pandas使用了一个在C
中实现的快速高效的解析器,以及一个目前功能更加完整的python实现。在可能的情况下,pandas使用C解析器(指定为engine='C'
),但如果指定了不支持C的选项,则可能会使用python。目前,不支持C语言的选项包括:
- 除单个字符以外的sep(例如正则表达式分隔符)
- 滑雪鞋
- sep=None,delim\u空格=False
engine='python'
显式选择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