title: Pandas apply - Re-using apply result to save time
body: <p>I am trying to make a new column on a subset of my data-frame that is relatively small (~600 rows) using the apply function and it works but it is slow because the apply function is computationally intensive and I cannot make this black-box function faster / less complex. </p>
  
  <p>However, a lot of the results returned by this black-box function are actually the same (close to 90%) because the inputs are the same. Therefore, is there a way to simply re-use the returned value if the given input is the same to save time?</p>
  
  <p>Here is the code that works but is slow:</p>
  
  <pre><code>df.loc[df['number']&gt;=10, 'value'].apply(lambda x: black_box(x).get())
  </code></pre>
  
  <p>Again, most values in the column <code>value</code> are identical, resulting in the same output.</p>