Given this dataframe below,
Is there a way to retrieve the columns having start values >= 20000 and stop values <= 40000?
Where start and stop are the names (not values) of the columns.
1 Answer
I think you can use get_level_values + astype to int (if necessary), create mask with & and last select by loc:
mask1 = df.columns.get_level_values('start').astype(int) >= 20000
mask2 = df.columns.get_level_values('stop').astype(int) <= 40000
mask = mask1 & mask2
df = df.loc[:, mask]
print (df)
