How can one use a logical index (or any other efficient method) to select columns for which the column name contains a certain match to a regular expression.
For example,
raw = ''' id 0_date 0_hr 1_date 1_hr
1 a 21-Jan 30 2-Mar 75
'''
import pandas as pd
from StringIO import StringIO
df = pd.read_table(StringIO(raw),header=0,index_col=[0],sep="\s+")
I would like to create a new dataframe with only the id column and all columns that contain the string "date". I was not able to use str.contains on df.columns. It seems the filter function works, but I wanted to create the logical index if that is a valid method. Thanks.