title: Groupby and Modify Pandas Dataframe Columns
body: <p>I have been at it for few hours now, and unfortunately haven't been able to do it in an efficient way. I am sorry, it seems like elementary. I need to groupby a dataframe on two columns and change another subset of columns(from the same dataframe) depending on the value of yet another column in the same dataframe.</p>
  
  <p>My dataframe looks like below:</p>
  
  <pre><code>state | binned_age   | mnth1 | mnth2 | key
   NSW  |  24-34       | 400   | 200   | 250
   VIC  |  65-150      | 150   | 200   | 450
   VIC  |  65-150      | 50    | 200   | 450
   VIC  |  65-150      | 600   | 200   | 450
   VIC  |  65-150      | 900   | 200   | 450
  </code></pre>
  
  <p>I'm trying to transform this dataframe like so:
  1) group on <code>state</code> and <code>binned_age</code>
  2) where <code>month1</code> and <code>mnth2</code> are greater than <code>key</code>, replace with <code>1</code>, elsewhere, replace with <code>0</code></p>
  
  <p>Final result should look like this:</p>
  
  <pre><code> state | binned_age   | mnth1 | mnth2 | key
       NSW  |  24-34       | 1     | 0     | 250
       VIC  |  65-150      | 0     | 0     | 450
       VIC  |  65-150      | 0     | 0     | 450
       VIC  |  65-150      | 1     | 0     | 450
       VIC  |  65-150      | 1     | 0     | 450
  </code></pre>
  
  <p>I am at this stage, but not sure how I can transform it to above dataframe.</p>
  
  <pre><code>grouped_df = sample_cols.groupby(['state', 'binned_age'])
  grouped_df.apply(lambda x: x.max_exp_1_mnth &gt; x.max_exp_2_mnth)
  </code></pre>
  
  <p>Thanks for all the help.</p>