title: How to get the first line of a group in Python
body: <p>New to Python.</p>
  <p>I have 2 dataframes</p>
  <p>The first is called df_my
  and it looks like this</p>
  <pre><code>ICD   Distance  ID   Grp
  -------------------------
  AB    0         1     1
  JG    0         4     1
  NH    1         5     2
  UY    1         7     1
  SS    2         9     1
  ED    2         14    2
  KK    2         15    3
  QR    3         18    3
  XZ    3         19    1
  FD    4         22    1
  LN    5         24    4
  TT    5         31    2
  </code></pre>
  <p>the other dataframe called df_Map and looks like this</p>
  <pre><code>0    1
  --------
  JG   838
  LN   228
  SS   699
  FD   100
  ED   483
  QR   594
  AB   349
  NH   777
  KK   505
  TT   866
  </code></pre>
  <p>What I am trying to do is this</p>
  <p>First, to get the first record of each group from df_my ordered by id or records with distance bigger than 3</p>
  <p>so it should become like this</p>
  <pre><code>ICD   Distance  ID   Grp
  -------------------------
  AB    0         1     1   &lt;== First of its group
  NH    1         5     2   &lt;== First of its group
  KK    2         15    3   &lt;== First of its group
  FD    4         22    1   &lt;== Distance &gt; 3
  LN    5         24    4   &lt;== Distance &gt; 3
  TT    5         31    2   &lt;== Distance &gt; 3
  </code></pre>
  <p>after that I want to match it with df_Map</p>
  <p>so it will be</p>
  <pre><code>ICD   Distance  ID   Grp    Map
  --------------------------------
  AB    0         1     1     349
  NH    1         5     2     777
  KK    2         15    3     505
  FD    4         22    1     100
  LN    5         24    4     228
  TT    5         31    2     866
  </code></pre>
  <p>I wonder how to do that</p>
  <p>I started with this</p>
  <pre><code>df_Final = df_my(Distance&gt;3)
  </code></pre>
  <p>but I did not know how to start with the first record in the group?</p>