Let's say I have a list of numbers, and I want the mean of all numbers that are greater than the 95th percentile. Is there some standard term for that value? ("Mean of a histogram bin"? "Conditional mean" on something?)

Is there a pandas standard library function to compute it?

  • $\begingroup$ I guess you can have it with pandas groupby and other functions, but I'm not talented enough to give you an answer. I'd suggest you posting in Stack Overflow for such a thing since that's a code question and there are way more people answering Pandas questions than here $\endgroup$ – BeamsAdept Aug 21 at 14:23
  • 1
    $\begingroup$ @BeamsAdept I think I would be able to implement it somehow, it's just that there are some subtleties around how to choose the cutoff (> or >= the 95th percentile?) and how to handle NaNs. I was asking for standard terminology to see if someone else has put more thought into these choices. Given that this is what I'm looking for, do you still think I should be asking on Stack Overflow instead? $\endgroup$ – dankness Aug 21 at 14:58

I don't think there is a standard library for it.

You can just skip nan value as mean treat them as zero which can mess up the result.

import pandas as pd
df=pd.DataFrame(lst) #For a given list
df[df >= df.quantile(.95)].mean(skipna=True)
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.