Skip to content
Advertisement

Cumulative of last 12 months from latest communication date?

I’m looking at counting the number of interactions grouped by ID in the last 12 months for each unique ID. The count starts from the latest date to the last one grouped by ID.

JavaScript

Output is something like the below.

JavaScript

How can I achieve this in Pandas? Any function that would count the months based on the dates from the latest date per group?

Advertisement

Answer

Use:

JavaScript

Or:

JavaScript

For count multiple columns use named aggregation:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement