Assume there is a pandas Series containing values reflecting categories ('a','b','c' or 1,2,3):
pds = I.pd.Series(['a','a','b','c','c','c','a'])
I would like to generate a new Series, which indicates how often each element has already occured, i.e. the expected output would be:
pds_result = I.pd.Series([0,1,0,0,1,2,2])
# ^ no 'a' prior to this position in pds
# ^ one 'a' prior to this position in pds
# ^ no 'b' prior to this position in pds
# ^ two 'a' prior to this position in pds
How can this be achieved in a concise manner?