Similar to this question, I have a feature 'preWeight' which has multiple observations for each MotherID, I want to transform this to dataframe to a new datframe where
- I assign preWeight a value of "Yes" if preWeight>=4000 for a particular MotherID regardless of the remaining observations
- Otherwise if preWeight is <4000 for a particular MotherID, I will assign preWeight a value of "No"
So I want to transform this dataframe:
ChildID MotherID preWeight
0 20 455 3500
1 20 455 4040
2 13 102 2500
3 13 102 NaN
4 702 946 5000
5 82 571 2000
6 82 571 3500
7 82 571 3800
Into this:
ChildID MotherID preWeight
0 20 455 Yes
1 13 102 No
2 702 946 Yes
3 82 571 No
I have tried this:
df.groupby('MotherID')['preWeight'].apply(
lambda x: 'Yes' if x>4000 in x.values else 'No').reset_index()
Bu I am getting the following error:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Thanks in advance.