Python pandas filter by column name and drop column if inferior as reference column value

Question:

I want to drop all column that contain PP in the name if their values are inferior or equal to the column ‘price’.

I think need to exclude the highPrice column and lowPrice column because they does not contain PP.
and use something like this:

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

but i dont know how to do the filter thing and how to include it.

Here is my df:

price   highPrice     lowPrice     PP_1     PP_2     PP_3     PP_4    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

my expected result is:

price   highPrice     lowPrice     PP_5     PP_6     PP_7
  1.1         1.2          1.0      1.1      1.5      2.2
Asked By: One boy

||

Answers:

Filter columns with PP for greter or equal like lowPrice by DataFrame.filter, get all missing columns with DataFrame.reindex and filter columns by DataFrame.loc:

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
Answered By: jezrael
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.