Reputation: 123
I am trying to filter a pandas dataframe using a function and am running into SettingWithCopyWarning warning. I was wondering if there was a better way of doing this. Below is a general outline of my code:
def cleanData(data):
out = data.query("data.x < 100")
out.z = out.z == "Z"
return out
data = cleanData(data)
I would like to be able to keep it in this function form, as I want to run the function on both my train and test data. Thanks :)
Upvotes: 1
Views: 104
Reputation: 3130
Just use .copy()
:
def cleanData(data):
out = data.query("data.x < 100").copy()
out.z = out.z == "Z"
return out
data = cleanData(data)
Upvotes: 3