I'm trying to add a "Monthly orders" column which calculates how many transactions a customer with specific id had within a specific CohortDate.
Basically, it's a COUNTIFS function where RANGES are all IDS and all CohortDates equal to ID and CohortDate of any given row.
Any help is much appreciated.
import pandas as pd
import numpy as np
df = pd.DataFrame({'order_id': [75054,75057,75059,75061,75066],
                   'customer_id': [101692,101694,101734,101692,101694],
                   'CohortDate': ['2016-05','2016-05','2016-05','2016-05','2016-06'] 
                  })
The result I would aim to get is the following:
order_id    customer_id    CohortDate    Monthly_orders
75054    101692    '2016-05'    2
75057    101694    '2016-05'    1
75059    101734    '2016-05'    1
75061    101692    '2016-05'    2
75066    101694    '2016-06'    1
 
    