Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I want the maximum number of transactions by each customer to a single merchant so I grouped the table by cid after that I am taking the number of times transactions is done by value_counts() which gives repeatition count but how can i get only max values for each cid out of it.

What I have tried:

Python
df.groupby('cid')['merchant'].value_counts()
Posted
Updated 9-Nov-21 1:52am
v2
Comments
Ashutosh sharma Sep2021 29-Sep-21 15:33pm    
df.groupby('cid')['merchant'].value_counts().head(1) is not working
Patrice T 29-Sep-21 15:46pm    
Use Improve question to update your question.
So that everyone can pay attention to this information.
Richard MacCutchan 30-Sep-21 4:37am    
You need to show the structure of the datatable, and your code.
Richard MacCutchan 30-Sep-21 4:44am    
Try:
df.groupby('cid')['merchant'].max()

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900