title: Python querying closest value row repeatedly in Pandas
body: <p>I have seen a similar question for a single query: <a href="https://stackoverflow.com/questions/30112202/how-do-i-find-the-closest-values-in-a-pandas-series-to-an-input-number">Closest Value in Pandas Series</a></p>
  
  <p>I need to do something similar, but for multiple queries.</p>
  
  <p>I have a column of data which is like a time input, and then another column which is supposed to act like a function.</p>
  
  <p>For Eg:</p>
  
  <pre><code>df = pd.concat([pd.Series(np.random.rand(51), name = 'f'), pd.Series(np.sort(np.random.choice(range(150), 51, replace=False)), name = 't')], axis = 1)
  </code></pre>
  
  <p>Which gives the first five rows like:</p>
  
  <pre><code>df.head()
          f       t
  0   0.459344    0
  1   0.675319    3
  2   0.481433    8
  3   0.373959    12
  4   0.554812    14
  </code></pre>
  
  <p>Basically column f is like a function, it's value in the interval [0, 3) is 0.459344 and in the interval [3,8) it is 0.675319.</p>
  
  <p>I am using a custom library for integration which will repeatedly query the function value at a given time, in order with a fixed step, say 0.05.
  I have to provide it with the value of the function at that time.</p>
  
  <p>for eg: the first 5 queries will be 0, 0.05, 0.1, 0.15, 0.2, all of which should return 0.459344</p>
  
  <p>How can i achieve this without repeated searches, in an optimal way?</p>
  
  <p><strong>EDIT</strong>: Clarification of Input and Output format.</p>
  
  <p>I have to create a function that should take the time as input, and output the function value.</p>
  
  <p>The input time can be a float it most definitely will be because the timesteps will be about 0.05.</p>
  
  <p>For Eg:</p>
  
  <p>Let us assume that i have created a function FunF, which does what i want.</p>
  
  <p>It will be called by external library like this</p>
  
  <pre><code>FunF(0) - # This should return 0.459344
  FunF(0.05) - # This should return 0.459344
  FunF(0.1) - # This should return 0.459344
  FunF(0.15) - # This should return 0.459344
   ...
   ...
   ...
  FunF(2.95) - # This should return 0.459344
  FunF(3) - # This should return 0.675319
  FunF(3.05) - # This should return 0.675319
  </code></pre>
  
  <p>and so on.</p>
  
  <p>I need to write the function FunF.</p>