title: How can I get the max value from one column where values match another column?
body: <p>I have a very large dataframe where one column has a set of names in it. Unfortunately, the same column also has some other data there. What I want to do is to find all the rows that contain the names, look for those in another column, get the max value from a third column. Then, I need to place that value in the same row as the name.</p>
  
  <p>I'm currently using a <code>for</code> loop, which does exactly what I want, but it is extremely slow. I've tried fooling around with <code>lookup</code> but can't get it to work. Just bear in mind that the real dataframe has something like 20,000 rows!</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  
  friends = ['Mickey', 'Minnie', 'Goofy', 'Donald', 'Daisy', 'Pluto']
  
  df_data = {'Name':['Mickey', 'Ravens', 'Vikings',
                      'Minnie', 'Packers', 'Browns',
                      'Goofy', 'Cowboys', 'Steelers',
                      'Donald', '49ers', 'Bears',
                      'Daisy', 'Chiefs', 'Raiders',
                      'Pluto', 'Patriots', 'Colts'],
          'Owner': [np.nan, 'Mickey', 'Mickey',
                      np.nan, 'Minnie', 'Minnie', 
                      np.nan, 'Goofy', 'Goofy', 
                      np.nan, 'Donald', 'Donald',
                      np.nan, 'Daisy', 'Daisy',
                      np.nan, 'Pluto', 'Pluto'],
          'Wins': [np.nan, 14, 10,
                  np.nan, 13, 6,
                  np.nan, 8, 8,
                  np.nan, 13, 8,
                  np.nan, 12, 7,
                  np.nan, 12, 7]}
  
  df = pd.DataFrame(data = df_data)
  
  for f in friends:
      df.loc[df['Name'] == f, 'Wins'] = df.loc[df['Owner'] == f, 'Wins'].max()
  
  print(df.to_string())
  </code></pre>