my problem is closely related to Groupby count only when a certain value is present in one of the column in pandas.
Let's say I have a dataframe which is sorted by not_unique_id and date_of_call.
rng = pd.date_range('2015-02-24', periods=8, freq='D')
df = pd.DataFrame(
{
"unique_id": ["K0", "K1", "K2", "K3", "K4", "K5", "K6","K7"],
"not_unique_id": ["A000", "A111", "A222", "A222", "A222", "A222", "A222","A333"],
"date_of_call": rng,
"customer_reached": [1,0,0,1,1,1,1,1],
}
)
df.sort_values(['not_unique_id','date_of_call'], inplace=True, ascending=False)
df.reset_index(drop=True, inplace=True) # reset index
df.head(10)
Now I want to add a new column which tells me, how often the customer was called successfully in the past. In other words: count how many times to customer was reached in the past and save result in new column. For the provided example, this would be the result:
How would you do it?

