Get column names for the N Max/Min values per row in Pandas
问题 I am trying to get, for each individual row, the name of the column with the max/min value up to N-values. Given something like this: a b c d e 1.2 2 0.1 0.8 0.01 2.1 1.1 3.2 4.6 3.4 0.2 1.9 8.8 0.3 1.3 3.3 7.8 0.12 3.2 1.4 I can get the max with idxmax(axis=1) and so on the min with idxmin(axis=1) but this only works for the top-max and bottom-min, not generalizable for N-values. I want to get, if called with N=2: a b c d e Max1 Max2 Min1 Min2 1.2 2.0 0.1 0.8 0.1 b a c e 2.1 1.1 3.2 4.6 3.4