title: Passing Pandas as Variable changes it
body: <p><strong>Revised question</strong>: How to pass a pandas dataframe in to a function, then work with that dataframe without changing the original/global version.</p>
  
  <p><strong>Answer</strong>: Appears to be that it depends on the type of action you are performing and so in my opinion not possible without risking something changing. See <a href="https://stackoverflow.com/questions/38895768/python-pandas-dataframe-is-it-pass-by-value-or-pass-by-reference">this</a> and <a href="https://stackoverflow.com/questions/13419822/pandas-dataframe-copy-by-value">this</a></p>
  
  <p>I will post what I believe to be the correct handling for this situation below once I've confirmed it.</p>
  
  <p><strong>Original question:</strong></p>
  
  <p>This is something I expect has been asked before but for my research it seems I'm getting results that contradict convention.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>xTest = pd.DataFrame({'A' : ['Test']})
  def MyFunction():
      _xTest=xTest
      _xTest['yPred'] = 1
  
      return _xTest
  
  res=MyFunction()
  xTest.head()
  </code></pre>
  
  <p>After it runs, xTest.head() shows that the 'yPred' column has been appended to it.
  From reading into Python scoping such as the URL below as well as somewhere else, I'm led to believe this should not be happening?</p>
  
  <p><a href="https://stackoverflow.com/questions/30684364/python-variable-scope-approach">Python variable scope approach</a></p>