Код: Выделить всё
col1 col2 col3 col4
Animal Tiger Cat Dog
Name Adam Grace Julia
Street Name1 Pine St Crown St Palm Ave
Street Name2 Grey St Tree St New St
Color Green Blue Yellow
Interest Yes No Yes
Low Interest No No Yes
High Interest Yes No Yes
City2 x z y
City1 m r t
Код: Выделить всё
col1 col2 col3 col4
Name Adam Grace Julia
Street Name1 Pine St Crown St Palm Ave
Street Name2 Grey St Tree St New St
City1 m r t
City2 x z y
Interest Yes No Yes
High Interest Yes No Yes
Low Interest No No Yes
Animal Tiger Cat Dog
Color Green Blue Yellow
Код: Выделить всё
order = ['Name', 'Street Name', 'City', 'Interest','High Interest','Low Interest', 'Animal', 'Color']
df['order'] = df['col1'].apply(order)
df = df.sort_values(by = 'order').drop(columns = 'order')
Код: Выделить всё
col1 col2 col3 col4
Street Name1 Pine St Crown St Palm Ave
Street Name2 Grey St Tree St New St
Name Adam Grace Julia
Подробнее здесь: https://stackoverflow.com/questions/791 ... -in-column
Мобильная версия