title: Pandas Return Conditional Value
body: <p>just need a little bit of help in returning some values from a dataframe.</p>
  
  <hr>
  
  <p>I've got a dataframe (call it df1) with some values:</p>
  
  <pre><code>ID      X    Y    Distance   Date
  1       1    2    2.2        01/01/2000
  2       2    3    1.8        02/02/2001
  3       3    4    1.2        03/03/2002
  4       4    5    2.7        04/04/2003 
  5       5    6    3.8        05/05/2004
  </code></pre>
  
  <p>Currently I have code which creates a new column - df1['Within 2k'] - which returns True if the Distance is within 2 km. For example, this would look like:</p>
  
  <pre><code>df1['Within 2k'] = df1['distance'] &lt;= 2
  print("df1")
  
  ID      X    Y    Distance   Date         Within 2k
  1       1    2    2.2        01/01/2000   False
  2       2    3    1.8        02/02/2001   True
  3       3    4    1.2        03/03/2002   True
  4       4    5    2.7        04/04/2003   False
  5       5    6    3.8        05/05/2004   False
  </code></pre>
  
  <p>I also have code which changes ID &amp; Distance to "Null" if they aren't within 2km. For instance, this looks like:</p>
  
  <pre><code>df1['ID'] = np.where((df1['Distance'] &lt;= 2), df1['ID'], "Null")
  df1['Distance'] = np.where((df1['Distance'] &lt;= 2), df1['Distance'], "Null")
  print(df1)
  
  ID     X    Y    Distance   Date
  Null   1    2    Null       01/01/2000
  2      2    3    1.8        02/02/2001
  3      3    4    1.2        03/03/2002
  Null   4    5    Null       04/04/2003 
  Null   5    6    Null       05/05/2004
  </code></pre>
  
  <hr>
  
  <p>The aim of my code is to return the first record (chronologically) where the distance is within 2km. Currently I have code which returns the value where the Date value is minimum, however that includes Null values.</p>
  
  <p>My code at the moment looks a bit like this:</p>
  
  <pre><code>Site2km = df1.loc[df1['Date'].idxmin(),'ID']
  Dist2km = df1.loc[df1['Date'].idxmin(),'Distance']
  
  return pd.Series([Site2km, Dist2km])
  </code></pre>
  
  <p>I need some code which will:</p>
  
  <p>1) Return the first ID &amp; Distance where the Distance is less than 2</p>
  
  <p>2) If every value in the table is outside the Distance 2km, return the strings "Null" for both ID &amp; Distance.</p>