Deshwal
Deshwal

Reputation: 4152

Trim Series/DataFrame on the basis of quantile values

Is there any mrthod in pandas to trim the Series/DataFrame based on the quantile values?

For Example if I have a ser=pd.Series([1,2,3,4,5,6,7,8])

how can I get the series where the data is between 0.27>Data>0.82 of the original ser?

Upvotes: 2

Views: 215

Answers (1)

jezrael
jezrael

Reputation: 862581

I think you need Series.between with Series.quantile:

a = ser.quantile([0.27, 0.82])
print (a)
0.27    2.89
0.82    6.74
dtype: float64

s,e = a
out = ser[ser.between(s, e, inclusive=False)]
print (out)
2    3
3    4
4    5
5    6
dtype: int64

Or:

out = ser[ser.between(ser.quantile(0.27), 
                      ser.quantile(0.82), inclusive=False)]

Upvotes: 3

Related Questions