gpt4 book ai didi

python - 根据分位数值修剪 Series/DataFrame

转载 作者:太空宇宙 更新时间:2023-11-03 23:54:44 27 4
gpt4 key购买 nike

pandas 中是否有任何方法可以根据分位数值修剪 Series/DataFrame

例如,如果我有一个 ser=pd.Series([1,2,3,4,5,6,7,8])

如何获取原始 ser0.27>Data>0.82 之间的系列?

最佳答案

我想你需要Series.betweenSeries.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

或者:

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

关于python - 根据分位数值修剪 Series/DataFrame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58282780/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com