Python 如何使用另一个熊猫系列从熊猫数据框返回索引列表?
我使用的是,我有下面的代码来计算四分位范围Python 如何使用另一个熊猫系列从熊猫数据框返回索引列表?,python,pandas,pandas-groupby,Python,Pandas,Pandas Groupby,我使用的是,我有下面的代码来计算四分位范围 # bin by area df['sqft_area_binned']=pd.cut(x=df['sqft_living'], bins=5) q1 = df.groupby(['sqft_area_binned'])['price'].quantile(0.25) q3 = df.groupby(['sqft_area_binned'])['price'].quantile(0.75) iqr = q3 - q1 upper = q3 + 1.5*
# bin by area
df['sqft_area_binned']=pd.cut(x=df['sqft_living'], bins=5)
q1 = df.groupby(['sqft_area_binned'])['price'].quantile(0.25)
q3 = df.groupby(['sqft_area_binned'])['price'].quantile(0.75)
iqr = q3 - q1
upper = q3 + 1.5*iqr
lower = q1 - 1.5*iqr
print(upper)
>>>
sqft_area_binned
(276.75, 2940.0] 946000.0
(2940.0, 5590.0] 1900000.0
(5590.0, 8240.0] 4332500.0
(8240.0, 10890.0] 10210500.0
(10890.0, 13540.0] 10410000.0
Name: price, dtype: float64
现在我想返回一个id列表(dfdf
中的第一列),其中sqft\u区域bined
位于相应的下方
或相应的上方
例如,如果一栋房子(位于df
中的一行)的面积为sqft\u-binned=(276.752940.0]
和price
>946000.0,则返回id
使用过滤或.isin()
,这怎么可能呢
query = df.index[(df.sqft_area_binned == desiredBin) & (df.price > upperPriceBound)]