title: pandas get first row in DataFrame with condition
body: <p>I am using Pandas to work with large number of Data. I want to find the <strong>fastest way to get the first row in DataFrame with id</strong></p>
  
  <pre><code>I have 2 DataFrame:
  
  school_detail
  school_id detail1 detail2
  1         d11     d21 
  2         d12     d22 
  2         d13     d23
  4         d14     d24
  ...
  It has more than 20 million rows
  
  schools
  id school_name
  1  name1 
  2  name2
  3  name3
  4  name4
  ...
  It has 3 million rows
  </code></pre>
  
  <p>I need to loop through all rows in school_detail to set type for each row.</p>
  
  <pre><code>def get_type(s_detail):
     # I need to get school name here to calculate the type so I use
     school = schools[schools.id == s_detail.school_id] # To get school by id
  
  school_detail['type'] = school_detail.apply(lambda x: get_type(x), axis=1)
  </code></pre>
  
  <p>I have use <strong>%prun</strong> to check time for function get school by id. It is about <strong>0.03 sec</strong></p>
  
  <p>When I run with <strong>10000 rows</strong> of school_detail. It takes <strong>43 sec</strong>.</p>
  
  <p>If I run with 20 mil rows. It may take several hours.</p>
  
  <p><strong>My questions:</strong></p>
  
  <p>I want to find the better way to <strong>get school by id</strong> to make it run faster.</p>
  
  <p>The id column is unique. Do pandas use binary search in this column?</p>