title: How to update a results from a function incrementally in Python
body: <p>I have a function that takes  12 seconds to run. I have made the function as efficient as possible using numba etc.</p>
  <p>Are there any tricks for recalculating the function for only new data rows when new data is added incrementally to the end of the initial data set?</p>
  <pre><code>import pandas as pd
  import numpy as np
  import time
  
  def complex_func(data):
  
      a = my_func1(data)  # Complex slow to run
  
      b = my_func2(a)     # Complex slow to run
  
      return b
  
  def main():
  
      data = create_data()    # Data has millions of rows.
  
      starttime = time.time()
      while True:
          result = complex_func(data)
  
          data = append_new_row(data)
          
          time.sleep(60.0 - ((time.time() - starttime) % 5.0))
  </code></pre>