I am trying to get the index of the 6th element in series I.
This is how the head looks
United States 1.536434e+13
China 6.348609e+12
Japan 5.542208e+12
Germany 3.493025e+12
France 2.681725e+12
To get the 6th index name (6th country after sorting) I usually use s.head (6) and get the 6th index from there
s.head (6) gives me
United States 1.536434e+13
China 6.348609e+12
Japan 5.542208e+12
Germany 3.493025e+12
France 2.681725e+12
United Kingdom 2.487907e+12
and looking at it, I get an index like the United Kingdom.
So, is there a better way to get an index other than this. And also for the data frame, is there any function to get the 6th index based on the corresponding column after sorting.
If this is a data frame, I usually sort, create a new column called index and use reset_index, and then use the iloc attribute to get the 6th number (since it will use the range in the index after reset).
Is there a better way to do this using pd.Series and pd.DataFrame.
Thank.