Search code examples
pythonpandascsv

How to read file with space separated values in pandas


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


Solution

  • Add delim_whitespace=True argument, it's faster than regex.
    Note however that after pandas 2.2.0 this is deprecated and it's better to use sep="\s+"