title: how to extract digits from column names in a pandas dataframe?
body: <p>I have</p>
  <pre><code>df.columns
  Index(['location', 'date', 
         'deaths_2020_all_ages', 'average_deaths_2015_2019_all_ages',
         'deaths_2015_all_ages', 'deaths_2016_all_ages', 'deaths_2017_all_ages',
         'deaths_2018_all_ages', 'deaths_2019_all_ages', 'deaths_2010_all_ages',
         'deaths_2011_all_ages', 'deaths_2012_all_ages', 'deaths_2013_all_ages',
         'deaths_2014_all_ages', 'Week', 'deaths_2021_all_ages', 'w'],
        dtype='object')
  
  </code></pre>
  <p>I want to rename the deaths columns such as 'deaths_2014_all_ages' to '2014'.</p>
  <p>I have tried this</p>
  <pre><code>cols =[x for x in df.columns[df.columns.str.extract(r'([ab])?(\d)')]]
  
  # KeyError: 2
  </code></pre>
  <p>and</p>
  <pre><code>cols =[x for x in df.columns[df.columns.str.replace('[a-z]+_\d{4}_[a-z]+_[a-z]+', '\d{4}', regex=True)]]
  
  # KeyError: '\\d'
  # error: bad escape \d at position 0
  </code></pre>
  <p>any advice? thank you.</p>