Subset of columns and filter Pandas

You can use the boolean condition to generate a mask and pass a list of cols of interest using loc:

frame.loc[frame['DESIGN_VALUE'] > 20,['mycol3', 'mycol6']]

I advise the above because it means you operate on a view not a copy, secondly I also strongly suggest using [] to select your columns rather than as attributes via sot . operator, this avoids ambiguities in pandas behaviour

Example:

In [184]:
df = pd.DataFrame(columns = list('abc'), data = np.random.randn(5,3))
df

Out[184]:
          a         b         c
0 -0.628354  0.833663  0.658212
1  0.032443  1.062135 -0.335318
2 -0.450620 -0.906486  0.015565
3  0.280459 -0.375468 -1.603993
4  0.463750 -0.638107 -1.598261

In [187]:
df.loc[df['a']>0, ['b','c']]

Out[187]:
          b         c
1  1.062135 -0.335318
3 -0.375468 -1.603993
4 -0.638107 -1.598261

This:

frame[(frame.DESIGN_VALUE > 20) & (frame['mycol3','mycol6'])]

Won't work as you're trying to sub-select from your df as a condition by including it using &

Tags:

Python

Pandas