We can use transform
df['Col4']=df.Col3.eq('Yes').groupby([df.Col1,df.Col2]).transform('all').\
map({True:'Yes',False: 'No'})
Use:
df['Col4']=df.groupby(['Col1','Col2']).Col3.transform(lambda x: 'yes' if x.eq('yes').all() else 'no')
print(df)
Col1 Col2 Col3 Col4
0 1 aaa yes no
1 1 aaa no no
2 1 aaa yes no
3 4 bbb yes no
4 4 bbb no no
5 4 bbb yes no
6 7 ccc yes yes
7 7 ccc yes yes
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.