Skip to content
Advertisement

Counting number of rows between min and max in pandas

I have a simple question in pandas.

Lets say I have following data:

JavaScript

How do I count the number of rows which are between minimum and maximum value in column a? So number of rows (it is 3 in this case) which are between 1 and 10 in this particular case?

Thanks

Advertisement

Answer

IIUC, you could get the index of the min and max, and subtract 2:

JavaScript

output: 3

If the is a chance that the max is before the min:

JavaScript

Alternative it the order of the min/max does not matter:

JavaScript

update: index of the 2nd largest/smallest:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement