Python 熊猫按列名过滤,如果低于参考列值,则删除列



如果名称中包含 PP 的所有列的值低于或等于"价格"列,我想删除它们。

我认为需要排除高价格列和低价格列,因为它们不包含 PP。 并使用类似这样的东西:

df = df[df.filter <= df.price]

但是我不知道如何做过滤器的事情以及如何包含它。

这是我的 df:

price   highPrice     lowPrice     PP_1     PP_2
price   highPrice     lowPrice     PP_5     PP_6     PP_7
1.1         1.2          1.0      1.1      1.5      2.2
df = df.loc[:, df.filter(like='PP').ge(df['lowPrice'], axis=0).reindex(df.columns, fill_value=True, axis=1)]
print (df)
price  highPrice  lowPrice  PP_5  PP_6  PP_7
0    1.1        1.2       1.0   1.1   1.5   2.2
PP_5 PP_6 PP_7 1.1 1.2 1.0 0.1 0.2 0.3 0.8 1.1 1.5 2.2

我的预期结果是:

PP_3

过滤带有 greter 的PP列或相等的列,如lowPriceDataFrame.filter,获取所有缺少的DataFrame.reindex列,并按DataFrame.loc过滤列:

PP_4

最新更新