title: How to search a string in one pandas dataframe column as a substring in another dataframe column
body: <p>I have two pandas dataframes <code>df1</code> and <code>df2</code>. I need to create a new column in <code>df1</code> by searching <code>df2['B']</code> to see if <code>df1['A']</code> is a substring of <code>df2['B']</code>. If there is a match return the value of <code>df2['A']</code> for the new column in <code>df1['B']</code>.</p>
  
  <p>Below are sample dataframes</p>
  
  <p>df1</p>
  
  <pre><code>      A                  B           
  9.female.ceo.,ceo,       ?
  9.female.ned.,ned,
  9.female.ned.,chair,
  2.female.ed.,ned,
  2.female.ned.,ed,
  9.female.chair.,ceo,
  2.female.chair.,chair,
  </code></pre>
  
  <p>df2</p>
  
  <pre><code>     A                B
  ,ceo,ned,          2.male.chair.,ceo,ned,
  ,chair,ned,        2.male.ned.,chair,ned,  
  ,ned,              2.female.ed.,ned,
  ,ceo,chair,        6.female.ed.,ceo,chair,
  ,ed,ceo,           6.male.chair.,ed,ceo,
  ,ceo,chair,        9.female.ed.,ceo,chair,
  ,ceo,ned,          9.female.chair.,ceo,ned,
  ,chair,(in ft10),  9.male.ceo.,chair,(in ft10),
  </code></pre>
  
  <p>Merge wouldn't work in this case since <code>df1['A']</code> contains substring of <code>df2['B']</code></p>
  
  <p>Any help that points to the right direction will be very much appreciated.</p>
  
  <p><strong>Expected results</strong></p>
  
  <p>df1</p>
  
  <pre><code>      A                    B           
  9.female.ceo.,ceo,       
  9.female.ned.,ned,
  9.female.ned.,chair,
  2.female.ed.,ned,         ,ned,
  2.female.ned.,ed,
  9.female.chair.,ceo,      ,ceo,ned,
  2.female.chair.,chair,  
  </code></pre>