I'm having issues building a function that can take the values from a column in a dataframe and keep a counter for each distinct event.
I want to generate the column Cnt from the column Col.
My main issue is keeping the value of each counter (the counter for A, for B, for C,...) because the cardinality is quite high (thousands of distinct values and some a almost 3 million records).
I was considering, as a last resource the following:
1 - apply .unique() to the column and store that series in a variable var;
2 - Go through all rows of the dataframe applying the following: IF df.col = var.VALUE1,
3 - Go through all values of the series.
I was hoping if there is a function/way that can allow me to perform this operation a bit more efficiently.