title: Python pandas str.extract from multiple columns
body: <p>I'm trying to extract string pattern from multiple columns into a single result column using Pandas and str.extract.</p>
  
  <p>My sample dataframe is as follows.</p>
  
  <pre><code>field1   field2
  ab1234   ab1234
  ac1234   
  qw45     rt23
  c1234b   cb1234
  cv       1234dd
  ...
  </code></pre>
  
  <p>I want to extract the '1234' (EDIT: any 4 digits integer not just '1234') from either column (field1 and field2 in this case) into a new result column to have the desired result below</p>
  
  <pre><code>field1   field2   result
  ab1234   ab1234   1234
  ac1234            1234
  qw45     rt23     
  c1234b   cb1234   1234
  cv       1234dd   1234
  ...
  </code></pre>
  
  <p>I'm attempting to use pandas str.extract to obtain my desired result, however, I have been unsuccessful as follows.</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  import re
  
  
  df = pd.DataFrame({'field1':['ab1234','ac1234','qw45', 'c1234b', 'cv'], 
  'field2':['ab1234','','rt23','cb1234', '1234dd']})
  
  df['result'] = df[['field1', 'field2']].apply(lambda x: 
  x.str.extract(r'(\d{4})', flags = re.IGNORECASE, expand = 
  False)).any(axis=1)
  
  print(df)
  </code></pre>
  
  <p>The above only returns Boolean results. I'm wondering if the above can be converted to return actual pattern or are there other ways of tackling this problem?</p>
  
  <p>Thank you very much in advance.</p>
  
  <p>EDIT: Sorry I should mention the pattern could be any 4 digits integer not just '1234'. Thus, I want the result column to return these 4 digits.</p>