I have a dataframe, but I'm trying to add a new column which is a list of the column names in order of their values, for each row.
Searching has proved to be difficult, as the search terms have so much in common with doing a column sort overall. Instead, I'm trying to customize the list for each row.
df = pd.DataFrame([
  ["a",88,3,78,8,40  ],
  ["b",100,20,29,13,91  ],
  ["c",77,92,42,72,58  ],
  ["d",39,53,69,7,40  ],
  ["e",26,62,77,33,86  ],
  ["f",94,5,28,96,7  ]
], columns=['id','x1','x2','x3','x4','x5'])
have = df.set_index('id')
+----+-----+----+----+----+----+----------------------------+
| id | x1  | x2 | x3 | x4 | x5 |        ordered_cols        |
+----+-----+----+----+----+----+----------------------------+
| a  |  88 |  3 | 78 |  8 | 40 | ['x2','x4','x5','x3','x1'] |
| b  | 100 | 20 | 29 | 13 | 91 | ['x4','x2','x3','x5','x1'] |
| c  |  77 | 92 | 42 | 72 | 58 | …                          |
| d  |  39 | 53 | 69 |  7 | 40 | …                          |
| e  |  26 | 62 | 77 | 33 | 86 | …                          |
| f  |  94 |  5 | 28 | 96 |  7 | …                          |
+----+-----+----+----+----+----+----------------------------+
