title: Comparing (Sub)Strings of two columns in a DF
body: <p>I have a DF as shown below:</p>
  
  <pre class="lang-none prettyprint-override"><code>DF =
  id  token      argument1             argument2 
  1   Tza        Tuvia Tza             Moscow  
  2   perugia    umbria                perugia    
  3   associated the associated press  Nelson
  </code></pre>
  
  <p>I now want to compare the values of the columns <code>argumentX</code> and <code>token</code> and choose the value for the new column <code>ARG</code> accordingly.</p>
  
  <pre class="lang-none prettyprint-override"><code>DF =
  id  token      argument1             argument2    ARG
  1   Tza        Tuvia Tza             Moscow       ARG1
  2   perugia    umbria                perugia      ARG2
  3   associated the associated press  Nelson       ARG1
  </code></pre>
  
  <p>Here is what I tried:</p>
  
  <pre><code>conditions = [
  (DF["token"] == (DF["Argument1"])),
   DF["token"] == (DF["Argument2"])]
  
  choices = ["ARG1", "ARG2"]
  
  DF["ARG"] = np.select(conditions, choices, default=nan)
  </code></pre>
  
  <p>This only compares the entire String and matches if they are identical. Constructions such as <code>.isin</code>, <code>.contains</code> or using a helper column such as <code>DF["ARG_cat"] = DF.apply(lambda row: row['token'] in row['argument2'],axis=1)</code> did not work. Any ideas?</p>