Adding New Column To Pandas Df Based On Condition
I have the following dataset: ID Asset Boolean 1 'A' True 1 'B' False 1 'B' False 2 'A' True 3 'A' True 3 'A' True 3 'B'
Solution 1:
You can GroupBy
and transform
with all
:
df['Check'] = df.groupby('ID').Boolean.transform('all')
print(df)
ID Asset Boolean Check
0 1 A True False
1 1 B False False
2 1 B False False
3 2 A True True
4 3 A True False
5 3 A True False
6 3 B False False
7 3 B False False
8 4 A True True
9 4 A True True
10 5 A True False
11 5 B False False
Post a Comment for "Adding New Column To Pandas Df Based On Condition"