Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Average number of transactions per user per day

I have a dataframe of transactions:

user_id mcc_code    currency_rk transaction_amt transaction_dttm    transaction_date

I want to know mean of count transactions by user_id by day, how can I achieve this? I think I need mark continues ranges of dates and groupby on it (because df sorted by user_id).

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Let’s assume your dataframe is named df, writing

new_df = df.group_by(["user_id", "day"]).loc[:, whatever_transaction_is].transform("count")

will give you the count of transaction by user by day. Taking mean of new_df will lead to your desired output.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading