# What's the of all values above some percentile called? How do I get it in pandas?

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?

• 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 – BeamsAdept Aug 21 at 14:23
• @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? – dankness Aug 21 at 14:58

## 1 Answer

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)