I need to sort a dataframe based on the order of the second row.  For example:
import pandas as pd

data = {'1a': ['C', 3, 1], '2b': ['B', 2, 3], '3c': ['A', 5, 2]}
df = pd.DataFrame(data)
df

Output:
  1a 2b 3c
0  C  B  A
1  3  2  5
2  1  3  2

Desired output:
  3c 2b 1a
0  A  B  C
1  5  2  3
2  2  3  1

So the columns have been order based on the zero index row, on the A, B, C.
Have tried many sorting options without success.
Having a quick way to accomplish this would be beneficial, but having granular control to both order the elements and move a specific column to the first position would be even better.  For example move "C" to the first column.
Something like make a list, sort, move and reorder on list.
mylist = ['B', 'A', 'C']
mylist.sort()
mylist.insert(0, mylist.pop(mylist.index('C')))

Then sorting the dataframe on ['C', 'A', 'B'] outputting
  1a 3c 2b
0  C  A  B
1  3  5  2
2  1  2  3


Sort pandas dataframe columns on second row order
With the help of pyjedy and Stingher, I was able to resolve this issue. One of the problems was due to my input. The input consisted of lists instead of dictionaries, so I needed to transform it. As a result, I had indexes for rows and across the top for columns. Consequently, selecting elements from the list required obtaining the index.
import pandas as pd

def search_list_for_pattern(lst, pattern):
    for idx, item in enumerate(lst):
        if pattern in item:
            break
    return idx

data = [['1a', 'B', 2, 3], ['2b', 'C', 3, 1], ['3c', 'A', 5, 2]]
df = pd.DataFrame(data).transpose()
print(df)

#     0   1   2
# 0  1a  2b  3c
# 1   B   C   A
# 2   2   3   5
# 3   3   1   2

# Get the second row and convert it to a list
second_row = df.iloc[1, :].tolist()
print(second_row)

# ['B', 'C', 'A']

# Find the index of the column you want to move to the first position
target_column = search_list_for_pattern(second_row, "C")
print(target_column)

# 1

# Sort the list
sorted_columns = sorted(range(len(second_row)), key=lambda k: second_row[k])
print(sorted_columns)

# [2, 0, 1]

# Move the target column to the first position
sorted_columns.remove(df.columns.get_loc(target_column))
sorted_columns.insert(0, df.columns.get_loc(target_column))

# Reorder the columns of the DataFrame based on the sorted list
df = df.iloc[:, sorted_columns]
print(df)

#     1   2   0
# 0  2b  3c  1a
# 1   C   A   B
# 2   3   5   2
# 3   1   2   3

df.to_excel('ordered.xlsx', sheet_name='Sheet1', index=False, header=False)


