I can't wrap my head around why this seemingly trivial piece of code pandas code below yields a SettingWithCopyWarning
.
I have a DataFrame questions
that contains (among others) a result
column containing results to a list of closed questions: a "J" equals 1 point, an "O" equals zero points. I simply want to map J, O and other results to a zero, one, None scheme, and store the result in a new column:
def scoreMap(x):
if x == "J":
return 1
elif x == "O":
return 0
else:
return None
questions['closedCorrect'] = questions['result'].apply(scoreMap)
The results seem correct otherwise when I inspect them, but the warning makes me suspicious.
Can anyone indicate whether I am making a thinking error, or why the warning could/should be ignored in this case?