I have a dataframe that includes data from different age groups - and I want to remove all children (or keep all adults). So, I want to drop all rows which satisfy the condition:
df.age_category != "newborn" & != "child" & != "schoolage"
I know this question has been asked a couple of times and I have tried so many of the approaches on here (e.g. this, this, this, or this).
Each time I get the following error:
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
This happens even when I only use one condition, so it doesn't seem to be a problem with the or
/ and
statements. It also doesn't matter whether I assign the condition to a variable and then use that or if I use a loop with if statements. And it happens whether I want to get rid of children or keep the adults in the dataset, so it's not a problem with the df.drop()
function, either.