I have this fake dataset:
And I want to find how many times a combination of BirthDate and ZipCode occur, like so:
Now, my question is how can I find the positions in the dataset df where these occurences happen? For example, how can I find the position where 2000101 and 08002 are?
Thanks in advance.
Use GroupBy.agg if need aggregate for counts and for index values like list to new column Pos:
GroupBy.agg
Pos
df1 = (df.reset_index() .groupby(['BithDate','ZipCode']) .agg(RowNumber=('BithDate','size'), Pos = ('index',list)))
2.1m questions
2.1m answers
60 comments
57.0k users