I have a pandas dataframe indexed by date and and ID. I would like to:
- Identify the ID of additions and deletions between dates
- Add the ID to another dataframe with the date of the addition/deletion.
date ID value
12/31/2010 13 -0.124409
9 0.555959
1 -0.705634
2 -3.123603
4 0.725009
1/31/2011 13 0.471078
9 0.276006
1 -0.468463
22 1.076821
11 0.668599
Desired output:
date ID flag
1/31/2011 22 addition
1/31/2011 11 addition
1/31/2011 2 deletion
1/31/2011 4 deletion
I have tried Diff between two dataframes in pandas . I cannot get this to work on a grouped dataframe. I am unsure how to loop over each group, and compare to the previous group.