I'm trying to get the index of 6th item in a Series
I have.
This is how the head looks like:
United States 1.536434e+13
China 6.348609e+12
Japan 5.542208e+12
Germany 3.493025e+12
France 2.681725e+12
For getting the 6th index name (6th Country after being sorted), 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 this, I'm getting the index as United Kingdom.
So, is there any better way for getting the index other than this? And also, for a dataframe, is there any function to get the 6th index on basis of a respective column after sorting.
If it's a dataframe, I usually, sort, create a new column named index, and use reset_index
, and then use iloc
attribute to get the 6th (since it will be using a range in the index after reset).
Is there any better way to do this with pd.Series
and pd.DataFrame
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…