Reputation: 407
I want to read in a Pandas dataframe from csv, where there are single whitespaces inside column names and the separators are multiple whitespaces. How can I tell Pandas to use only more than one consecutive whitespace as separator but ignore single whitespaces?
Upvotes: 5
Views: 1607
Reputation: 150825
another option that I actually use, which saves me some shift
keypresses:
df = pd.read_csv('file.csv', sep='\s\s+')
Upvotes: 3
Reputation: 92904
With specific regex pattern for sep=
option:
df = pd.read_csv(sep='\s{2,}')
\s{2,}
- quantifier, matches any whitespace character between 2
and unlimited times, as many times as possibleUpvotes: 6