I want to order a DataFrame by increasing value of column number
, and get the indexof that highest value. (Here it's the second row, so the result should be 'BCD':
number L-word ID
ABC 1 Lord ABC works
BCD 25 Land BCD works
CDE 3 Loft CDE works
(Is there a solution that is not even remotely as weird as the following hack of mine? I worked around this by adding another column with the same name, just so that I understand how that could work in general) So here is the code I came up with:
numbers_ordered = df.sort_values(['number'], ascending = False, na_position='last')
df = numbers_ordered[:1]
a = dict(df.head())
b = a['ID']
b = str(b)
c = b[:2]
This seems to be incredibly awkward and there should be an easy option to do this, however I cannot find it in the documentation of pandas as well as the www. I had the idea of changing the index (something like df = df.reset_index()) and then turning the old index into a new column but that would still not be the ultimate solution since I think there should be an option to just "extract" the index of the top hit of my df?
Try df['number'].argmax()
output