title: Conditional grouping pandas DataFrame
body: <p>I have a DataFrame that has below columns:</p>
  
  <pre><code>df = pd.DataFrame({'Name': ['Abe', 'Karl', 'Billy', 'Abe', 'Karl', 'Billy', 'Abe', 'Karl', 'Billy'], 
                 'Lenght': ['10', '12.5', '11', '12.5', '12', '11', '12.5', '10', '5'],
                'Try': [0,0,0,1,1,1,2,2,2],
                'Batch':[0,0,0,0,0,0,0,0,0]})
  </code></pre>
  
  <p>In each <code>batch</code> a <code>name</code> gets arbitrary many tries to get the greatest <code>lenght.</code> 
  What I want to do is create a column <code>win</code> that has the value 1 for greatest <code>lenght</code> in a <code>batch</code> and 0 otherwise, with the following conditions.</p>
  
  <ul>
  <li><p>If one  <code>name</code> hold the greatest <code>lenght</code> in a batch in multiple <code>try</code> only the first <code>try</code> will have the value 1 in <code>win</code>(See "Abe in example above")</p></li>
  <li><p>If two separate <code>name</code> holds equal greatest <code>lenght</code> then both will have value 1 in <code>win</code> </p></li>
  </ul>
  
  <p>What I have managed to do so far is:</p>
  
  <pre><code>df.groupby(['Batch', 'name'])['lenght'].apply(lambda x: (x == x.max()).map({True: 1, False: 0}))
  </code></pre>
  
  <p>But it doesn't support all the conditions, any insight would be highly </p>
  
  <p>Expected outout:</p>
  
  <pre><code>df = pd.DataFrame({'Name': ['Abe', 'Karl', 'Billy', 'Abe', 'Karl', 'Billy', 'Abe', 'Karl', 'Billy'], 
                     'Lenght': ['10', '12.5', '11', '12.5', '12', '11', '12.5', '10', '5'],
                    'Try': [0,0,0,1,1,1,2,2,2],
                    'Batch':[0,0,0,0,0,0,0,0,0],
                    'win':[0,1,0,1,0,0,0,0,0]})
  </code></pre>
  
  <p>appreciated.
  Many thanks,</p>