Dmitry  Sokolov
Dmitry Sokolov

Reputation: 1383

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).

Upvotes: 0

Views: 475

Answers (2)

Dmitry  Sokolov
Dmitry Sokolov

Reputation: 1383

Answer:

transactions.groupby(["user_id", "transaction_date"])['currency_rk'].count().groupby(['user_id']).mean()

Upvotes: 2

Zelemist
Zelemist

Reputation: 640

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.

Upvotes: 1

Related Questions