Aggregate columns by date (sum) Per customer

Advertisements

Peace,
I have the data in the following table:
enter image description here

I need to get to the point where each row represents a client and the columns are months and each month the amount spent.
Something like that

Thanks!!

>Solution :

df['month'] = df.InvoiceDate.dt.to_period('M')
df.pivot_table(index='CustomerId', columns='month', values='TotalPrice', aggfunc='sum')

Leave a ReplyCancel reply