Sort a table with irregular column info in Python


#1

I have a messy table as per below, the data inside the table have integer and word/character. I want to sort the table from Info 5 to Info 1 .

Fruit Info 1 Info 2 Info 3 Info 4 Info 5
Apple q z 2
Grape w 4
Guava e 7 u
Kiwi r n s m

Wish to get the result table as below.

Fruit Info 1 Info 2 Info 3 Info 4 Info 5
Kiwi r n s m
Guava e 7 u
Apple q z 2
Grape w 4

I have tried to use the str.contains, however it couldn’t detect the integer.

i = ['Fruit', 'Info 1', 'Info 2', 'Info 3', 'Info 4', 'Info 5',] 

data[data[i].str.contains('', na=False)

python
dataframe
Sorting