Is there a way for read_csv
to auto-detect the delimiter? numpy's genfromtxt
does this.
My files have data with single space, double space and a tab as delimiters. genfromtxt()
solves it, but is slower than pandas' read_csv
.
Any ideas?
Option 1
Using delim_whitespace=True
df = pd.read_csv('file.csv', delim_whitespace=True)
Option 2
Pass a regular expression to the sep
parameter:
df = pd.read_csv('file.csv', sep='\s+')
This is equivalent to the first option