I have a list of DataFrames where I am outputting just the column names for each. I am able to sort each DataFrame by column name, but I also want to sort the list itself based on the name of the first column in each DataFrame. I've searched around but can't find what the appropriate key for sorted()
would be.
for df in df_list:
df = df.reindex(sorted(df.columns), axis=1)
sorted_dflist = sorted(df_list, key = ???)
My Output:
( 3 4 5 8 11 12)( 7 10)( 1 6 9 13 14)(2)
Expected Output:
( 1 6 9 13 14)(2)( 3 4 5 8 11 12)( 7 10)