ABC
ABC

Reputation: 45

Splitting on the columns of a dataframe with more than two whitespaces

I want to split all the columns of a dataframe with more than two whitespaces since all the columns have the same format. I know how to do the same on one or a few columns but stuck at implementing the same code on all the columns. The code below works for one column. Would really appreciate any help on this.

df2 = df1['Col 1'].str.split("\s{2,}",expand = True)

Upvotes: 1

Views: 126

Answers (1)

gilf0yle
gilf0yle

Reputation: 1102

simply do this:

df = df.apply(lambda x: x.str.split("\s{2,}",expand = True))

Upvotes: 1

Related Questions