How to find the answer to an operation within an index in Pandas

Screen Link:

rank_change =  f500["previous_rank"] - f500["rank"]

rank_change_max = rank_change.max()
rank_change_min = rank_change.min()



count    500.000000
mean     -28.366000
std      108.602823
min     -500.000000
25%      -28.250000
50%       -4.000000
75%        8.250000
max      226.000000
dtype: float64

I am trying to do a little extra for this mission out of curiosity.

Basically, I want to pull the max value of rank_change and use it to pull back the company that had that rank change. I feel like I’m overthinking the syntax but still can’t figure it out.

I was trying to do this syntax originally:


But that did not work for me.

Any help would be appreciated!!

Since rank_change is a Series, we can use a boolean filter.

rank_change[rank_change == rank_change_max]

Since the index of the rank_change series are the company names, you can get just the company name using .index[0] (since the result of .index is a list):

rank_change[rank_change == rank_change_max].index[0]

I’m not sure if there’s a better way, but this seemed to work. Thanks for the fun challenge!

1 Like

Thank you!! This helped a ton!

I was also able to get the same result by not using the .index[0]

print(rank_change[rank_change == rank_change_max])

Thanks for the help @april.g :smiley:

1 Like

Yep, the .index[0] isn’t necessary if you just want to see the result. I added it in there as an option because without it the result is a series with one row, and I wanted to see if I could just extract the string value by itself.

1 Like

Oh gotcha, thanks for the help! I spent an hour on this not realizing it was that easy O.o