I have dataframe like that. I need to choose and count all distinct users, who have title "banner_click" and "order". So I don't understand how to do it in pandas, in SQL you do like UniqExactIf and go on, there I need to find all users, who had both these title.
user title
0 user_0 banner_click # has both "banner_click" and "order"
1 user_0 order #
2 user_1 banner_show
3 user_1 order
4 user_2 order # also has both "banner_click" and "order"
5 user_2 banner_click #
I have tried "in" but I guess it doesn't work correct
main = df.query("title in ('banner_click','order')").agg({'user':'nunique'})
Expected output: 2
(user_0 and user2 are a match)
Reproducible example:
df = pd.DataFrame({'user': ['user_0', 'user_0', 'user_1', 'user_1', 'user_2', 'user_2'],'title': ['banner_click', 'order', 'banner_show', 'order', 'order', 'banner_click']})