根据熊猫中一列的百分位数范围过滤数据框

问题描述 投票:0回答:1

我有一个数据框,如下所示

ID     Price
1      5
2      90
3      20
4      40
5      30
6      70
7      60
8      100
9      80
10     50

从上面,我想将上面的数据框从10%过滤到90%,如下所示。

预期输出:

ID     Price
2      90
3      20
4      40
5      30
6      70
7      60
9      80
10     50
pandas pandas-groupby
1个回答
0
投票
使用between + Series.quantile

df[df['Price'].between(*df['Price'].quantile([0.1, 0.9]))] ID Price 1 2 90 2 3 20 3 4 40 4 5 30 5 6 70 6 7 60 8 9 80 9 10 50

© www.soinside.com 2019 - 2024. All rights reserved.