How to read file with space separated values in pa

2019-01-14 01:02发布

问题:

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+")