title: Filtering Pandas Dataframe Based on List of Column Names
body: <p>I have a pandas dataframe which has may be 1000 Columns. However I do not need so many columns&gt; I need columns only if they match/starts/contains specific strings.</p>
  <p>So lets say I have a dataframe columns like
  df.columns =</p>
  <pre><code>  HYTY, ABNH, CDKL, GHY@UIKI,  BYUJI@#hy  BYUJI@tt  BBNNII#5  FGATAY@J ....
  </code></pre>
  <p>I want to select columns whose name are only like HYTY, CDKL, BYUJI* &amp; BBNNI*</p>
  <p>So what I was trying to do is to create a list of regular expressions like:</p>
  <pre><code>  import re 
  
    relst = ['HYTY', 'CDKL*', 'BYUJI*', 'BBNI*']
  
  
    my_w_lst = [re.escape(s) for s in relst]
  
    mask_pattrn = '|'.join(my_w_lst)
  </code></pre>
  <p>Then I create the logical vector to give me a list of TRUE/FALSE to say whether the string is present or not. However,  not understanding how to get the dataframe of only those true selected columns from this.</p>
  <p>Any help will be appreciated.</p>