Calculate nunique() for groupby in pandas
问题 I have a dataframe with columns: diff - difference between registration date and payment date,in days country - country of user user_id campaign_id -- another categorical column, we will use it in groupby I need to calculate count distinct users for every country + campaign_id group who has diff <=n. For example, for country 'A', campaign 'abc' and diff 7 i need to get count distinct users from country 'A', campaign 'abc' and diff <= 7 My current solution(below) works too long import pandas