'finding combination of columns which maximizes a quantity
I have a dataframe which looks like this:
cuid day transactions
0 a mon 1
1 a tue 2
2 b tue 2
3 b wed 1
For each 'cuid' (customer ID) I want to find the day that maximizes the number of transactions. For e.g. for the above df, the output should be a df which looks like
cuid day transactions
1 a tue 2
2 b tue 2
I've tried code which looks like:
dd = {'cuid':['a','a','b','b'],'day':['mon','tue','tue','wed'],'transactions':[1,2,2,1]}
df = pd.DataFrame(dd)
dfg = df.groupby(by=['cuid']).agg(transactions=('transactions',max)).reset_index()
But I'm not able to figure out how to join dfg and df.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
