title: Alternative to nested np.where in Pandas DataFrame
body: <p>I have this code (which works) - a bunch of nested conditional statements to set the value in the <code>'paragenesis1'</code> row of a dataframe (<code>myOxides['cpx']</code>), depending on the values in various other rows of the frame.<br><br>
  I'm very new to python and programming in general. I am thinking that I should write a function to perform this, but how then to apply that function elementwise?  This is the only way I have found to avoid the 'truth value of a series is ambiguous' error.<br><br>
  Any help greatly appreciated!</p>
  <pre><code>myOxides['cpx'].loc['paragenesis1'] = np.where(
              ((cpxCrOx&gt;=0.5) &amp; (cpxAlOx&lt;=4)),
              &quot;GtPeridA&quot;, 
              np.where(
                      ((cpxCrOx&gt;=2.25) &amp; (cpxAlOx&lt;=5)), 
                      &quot;GtPeridB&quot;, 
                      np.where(
                              ((cpxCrOx&gt;=0.5)&amp;
                               (cpxCrOx&lt;=2.25)) &amp;
                               ((cpxAlOx&gt;=4) &amp; (cpxAlOx&lt;=6)),
                               &quot;SpLhzA&quot;,
                               np.where(
                                       ((cpxCrOx&gt;=0.5) &amp;
                                        (cpxCrOx&lt;=(5.53125 - 
                                                   0.546875 * cpxAlOx))) &amp;
                                        ((cpxAlOx&gt;=4) &amp; 
                                         (cpxAlOx &lt;= ((cpxCrOx - 
                                                       5.53125)/ -0.546875))),
                               &quot;SpLhzB&quot;,
                               &quot;Eclogite, Megacryst, Cognate&quot;))))
  </code></pre>
  <p>or;<br></p>
  <pre><code>df.loc['a'] = np.where(
              (some_condition),
              &quot;value&quot;, 
              np.where(
                      ((conditon_1) &amp; (condition_2)), 
                      &quot;some_value&quot;, 
                      np.where(
                              ((condition_3)&amp; (condition_4)),
                               &quot;some_other_value&quot;,
                                np.where(
                                        ((condition_5),
                                          &quot;another_value&quot;,
                                          &quot;other_value&quot;))))
  </code></pre>