I have a dataframe with a column in python:
df
columnA
Apple Banana
Orange Citron Pineapple
How can I reserve the order of the substrings based on the white spaces? The outcome should be:
columnA
Banana Apple
Pineapple Citron Orange
Right now, I am only using:
df['columnA'] = df['columnA'].replace(r'(\s+).(\s+).(\s+)',r'\3\2\1',regex=True)
but this only works if I know the number of substrings, this I do not know upfront.