Python - create a column to count and sum grouped transactions by Date, category, Name

55 views Asked by At

My data is from a CSV and is in a dataframe called "df". looks like this:

Date           Name                     Transaction Category              Amount
11/02/2020     Alannis                     A                                11.50
11/02/2020     Alannis                     B                                12.00
11/03/2020     Jordan                      C                                13.00  
11/03/2020     Jordan                      A                                13.00 
11/03/2020     Jordan                      C                                13.00 

I tried this:

df['DailyTransactions'] = df.groupby('Date)['Name'].transform('Count')

I realize that I'm missing some items. I wanted it to look like this, or similar:

Date            Name      Transaction Category    SUM        COUNT

11/02/2020      Alannis             A              23.50       2
11/03/2020      Jordan              C              26.00       2
11/03/2020      Jordan              A              13.00       1   

So in the end, I'd also like to see if these transactions surpass a certain amount, say $30.So did anyone spend more than $30 per day in total from categories A, B, and C??

I am open to trying anything, thanks in advance.

0

There are 0 answers