Reputation: 4152
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
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