在pandas read-cs中使用utf8记录分隔符

2024-10-02 02:34:34 发布

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

我有一个分隔文件,其中分隔符是NOT character (¬),我无法使用pandas解析它-请看下面,列没有正确拆分。在

test = pd.read_csv("file.csv", sep="¬", encoding="latin-1")
test.head(1)
0       1231�XXX7791�BBB9991�22999KKKK... 
test.shape
Out[128]: (7001001, 1)

我使用的是ipython3.2.0,pandas 0.16.2,2.7.10.final.0。在


Tags: 文件csvtestpandasreadnotheadsep
1条回答
网友
1楼 · 发布于 2024-10-02 02:34:34
import pandas as pd

df = pd.read_csv('data.csv', sep='\u00AC', encoding ='utf-8', header=None, engine='python')

print(df)

前面的代码会给我这个,这就是你想要的。您只需将正确的UTF-8编码称为sep

^{pr2}$

您需要engine=python,因为默认情况下,pandas使用不支持regex分隔符的engine=c。在

来自IPython

enter image description here

相关问题 更多 >

    热门问题