How to read file with space separated values in pandas

a 夏天 提交于 2019-12-17 08:57:09

问题


I try to read the file into pandas. The file has values separated by space, but with different number of spaces I tried:

pd.read_csv('file.csv', delimiter=' ')

but it doesn't work


回答1:


add delim_whitespace=True argument, it's faster than regex.




回答2:


you can use regex as the delimiter:

pd.read_csv("whitespace.csv", header=None, delimiter=r"\s+")


来源:https://stackoverflow.com/questions/19632075/how-to-read-file-with-space-separated-values-in-pandas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!