在 Python Pandas read_csv 中使用多字符分隔符 [英] Use Multiple Character Delimiter in Python Pandas read_csv

查看:75
本文介绍了在 Python Pandas read_csv 中使用多字符分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

熊猫 read_csv 函数似乎只允许使用单字符分隔符/分隔符.有没有办法允许使用字符串,例如*|*"或%%"?

It appears that the pandas read_csv function only allows single character delimiters/separators. Is there some way to allow for a string of characters to be used like, "*|*" or "%%" instead?

推荐答案

解决方案是使用 read_table 而不是 read_csv:

The solution would be to use read_table instead of read_csv:

1*|*2*|*3*|*4*|*5
12*|*12*|*13*|*14*|*15
21*|*22*|*23*|*24*|*25

所以,我们可以用:

pd.read_table('file.csv', header=None, sep='*|*')

这篇关于在 Python Pandas read_csv 中使用多字符分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆