title: two conditional variable and one numerical variable lambda function in pandas dataframe to create a new boolean column
body: <p>I have a Dataframe that I want to add an extra column which will be a Boolean output ('True' or 'False').</p>
  <p>The categorical variables, i.e. column names, in the Dataframe are 'chems' and 'lot' and the continuous variable is the column name 'value'.</p>
  <p>I want to use two of the categorical variables to assess and create the output 'True' or 'False' considering the values associated with the continuous variable 'value' and if the mean of one of the lots for a particular chemical (chems) is greater than the other. In this particular example, it would be: is the mean of lot 9849 &gt; lot 7711?</p>
  <p>Below is a snapshot of the pandas Dataframe relevant to the columns above and the expected output:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>chems</th>
  <th>lot</th>
  <th>value</th>
  <th>Boolean</th>
  <th>Average</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>AMCL1</td>
  <td>7711</td>
  <td>-0.01737</td>
  <td>TRUE</td>
  <td>-0.02433</td>
  </tr>
  <tr>
  <td>AMCL1</td>
  <td>7711</td>
  <td>0.014506</td>
  <td>TRUE</td>
  <td></td>
  </tr>
  <tr>
  <td>AMCL1</td>
  <td>7711</td>
  <td>-0.03482</td>
  <td>TRUE</td>
  <td></td>
  </tr>
  <tr>
  <td>AMCL1</td>
  <td>7711</td>
  <td>-0.05299</td>
  <td>TRUE</td>
  <td></td>
  </tr>
  <tr>
  <td>AMCL1</td>
  <td>7711</td>
  <td>-0.03097</td>
  <td>TRUE</td>
  <td></td>
  </tr>
  <tr>
  <td>AMCL1</td>
  <td>9849</td>
  <td>0.027269</td>
  <td>TRUE</td>
  <td>0.04055</td>
  </tr>
  <tr>
  <td>AMCL1</td>
  <td>9849</td>
  <td>0.05071</td>
  <td>TRUE</td>
  <td></td>
  </tr>
  <tr>
  <td>AMCL1</td>
  <td>9849</td>
  <td>0.043671</td>
  <td>TRUE</td>
  <td></td>
  </tr>
  <tr>
  <td>AmT</td>
  <td>7711</td>
  <td>0.025124</td>
  <td>FALSE</td>
  <td>0.032779</td>
  </tr>
  <tr>
  <td>AmT</td>
  <td>7711</td>
  <td>0.026267</td>
  <td>FALSE</td>
  <td></td>
  </tr>
  <tr>
  <td>AmT</td>
  <td>7711</td>
  <td>0.05459</td>
  <td>FALSE</td>
  <td></td>
  </tr>
  <tr>
  <td>AmT</td>
  <td>7711</td>
  <td>0.025135</td>
  <td>FALSE</td>
  <td></td>
  </tr>
  <tr>
  <td>AmT</td>
  <td>7711</td>
  <td>NaN</td>
  <td>FALSE</td>
  <td></td>
  </tr>
  <tr>
  <td>AmT</td>
  <td>9849</td>
  <td>-0.04318</td>
  <td>FALSE</td>
  <td>-0.04371</td>
  </tr>
  <tr>
  <td>AmT</td>
  <td>9849</td>
  <td>-0.04331</td>
  <td>FALSE</td>
  <td></td>
  </tr>
  <tr>
  <td>AmT</td>
  <td>9849</td>
  <td>-0.04463</td>
  <td>FALSE</td>
  <td></td>
  </tr>
  </tbody>
  </table>
  </div>
  <p><em>note, please ignore the column average here, that's the calculation I want to use to decide the outcome for the Boolean column.</em></p>
  <p>I'm nearly sure I can do this with a lambda expression but I haven't been able to capture with a lambda expression the two categorical variables for assessing the means. Currently, I have something like this:</p>
  <pre><code>df['Boolean'] = df['value'].apply\
      (lambda x: 'True' for chem in df['chems'] if np.mean(np.array(df[(df['lot'] == '9849')]['value'])) &gt; np.mean(np.array(df[(df['lot'] == '7711')]['value'])) else 'False')
  </code></pre>
  <p>I can't figure out the syntax at the end for the else 'False', I'm getting a SyntaxError: invalid syntax and I'm not sure the apply lambda function is even close to doing what I want it to do.</p>