Compare Rows Within a Group and Rank Best to Worst
I'm interested in an approach for comparing rows "within group" to produce a ranking from best to worst based on the performance relative to other rows within a group.
For example, if given this DataFrame:
import pandas as pd
pd.set_option('display.max_columns', 500)
d = {'L1': ['Group 1', 'Group 1', 'Group 1', 'Group 1', 'Group 1', 'Group 1',
'Group 1', 'Group 1', 'Group 1', 'Group 1', 'Group 1', 'Group 1',
'Group 1', 'Group 1', 'Group 1', 'Group 2', 'Group 2', 'Group 2',
'Group 2', 'Group 2', 'Group 2', 'Group 2', 'Group 2', 'Group 2',
'Group 2', 'Group 2', 'Group 2', 'Group 2', 'Group 2', 'Group 2',
'Group 2'],
'L2': ['ryxdgrdb', 'ryxdgrdb', 'tkgkrrfyydk-tk', 'tkgkrrfyydk-tk',
'tkgkrrfyydk-rrfyydk aa', 'tkgkrrfyydk-rrfyydk aa', 'tkgkvyykkdg-tk',
'tkgkvyykkdg-tk', 'tkgkvyykkdg-tk', 'tyyak ndb kaakg',
'tyyak ndb kaakg', 'tyyak ndb kaakg', 'tyyak ndb kaakg',
'tyyak ndb kaakgkdrf', 'tyyak ndb kaakgkdrf', 'tyyak-tyy', 'tyyak-tyy',
'tyyak-tyyak rrfy', 'tyyak-tyyak rrfy', 'tyyak-tyyak xfarya',
'tyyak-tyyak xfarya', 'tyyak-tyyak mdx', 'tyyak-tyyak mdx',
'tyyak-tyyak mdxm vyykk', 'tyyak-tyyak mdxm vyykk',
'tyyak-tyyak mdxm vyykk', 'tyyak-tyyak', 'tyyak-tyyak', 'tyyak-tyyak',
'tyyak-tyyak', 'tyyak-tyyak'],
'm1': [77758, 56926, 33338, 68575, 18628, 31271, 17594, 66825, 34408, 51986,
77681, 59951, 15777, 13475, 29964, 300474, 84509, 14220, 18346, 47370,
34887, 73741, 201882, 24374, 38197, 42884, 35621, <PHONE_NUMBER>, 14337, 92603,
686183],
'm2': [0.001325, 0.0057090000000000005, 0.041484, 0.028114999999999998,
0.014011000000000001, 0.008378, 0.021712000000000002,
0.033714999999999995, 0.033306, 0.026392000000000002, 0.021447,
0.022969, 0.020916999999999998, 0.056401, 0.063209, 0.039478, 0.045534,
0.055555999999999994, 0.028671, 0.021490000000000002, 0.019492,
0.027270999999999997, 0.033272, 0.023755000000000002, 0.016729,
0.016393, 0.006878, 0.034549, 0.024622, 0.018304, 0.018087],
'm3': <PHONE_NUMBER>, <PHONE_NUMBER>, <PHONE_NUMBER>, 1.<PHONE_NUMBER>, 1.5906130269999998,
<PHONE_NUMBER>, 1.13091623, <PHONE_NUMBER>, 1.<PHONE_NUMBER>, 1.208360058,
<PHONE_NUMBER>, <PHONE_NUMBER>, 1.3567272730000002, <PHONE_NUMBER>, <PHONE_NUMBER>,
0. 60