Revised question: How to pass a pandas dataframe in to a function, then work with that dataframe without changing the original/global version.
Answer: 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 this and this
I will post what I believe to be the correct handling for this situation below once I've confirmed it.
Original question:
This is something I expect has been asked before but for my research it seems I'm getting results that contradict convention.
Here is my code:
xTest = pd.DataFrame({'A' : ['Test']})
def MyFunction():
_xTest=xTest
_xTest['yPred'] = 1
return _xTest
res=MyFunction()
xTest.head()
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?