title: make a copy of dataframe inside function without changing original
body: <p>I'm trying to create a function that can change the values of a dataframe copy without changing the original dataframe. This is what I have so far:</p>
  
  <pre><code>def home_undervalued(df):
      local_df = df
      local_df['total_games'] = 0
      local_df['total_wins'] = 0
      cond_1 = local_df['predicted_spread'] &gt; local_df['vegas_spread']
      cond_2 = local_df['actual_spread'] &gt; local_df['vegas_spread']
      cond_3 = local_df['predicted_spread'] - local_df['vegas_spread'] &gt;= 3
  
      local_df.loc[cond_1 &amp; cond_3 , 'total_games'] = 1
      local_df.loc[cond_1 &amp; cond_2 &amp; cond_3 , 'total_wins'] = 1
  
      total_games = sum(local_df.total_games)
      total_wins = sum(local_df.total_wins)
  
      return float(total_wins) / float(total_games)
  </code></pre>
  
  <p>I then call the function with</p>
  
  <pre><code>home_undervalued(df)
  </code></pre>
  
  <p>It seems to work, but then I realize the values for df['total_games'] and df['total_wins'] have changed. I'm trying to change the values for local_df, but preserve the values df. Any ideas on how to fix this?</p>