I have a pandas dataframe which contains data as shown below:
ID year_month_id Class
1 201612 A
2 201612 D
3 201612 B
4 201612 Other
5 201612 Other
6 201612 Other
7 201612 A
8 201612 Other
9 201612 A
1 201701 B
So an ID can be under any class in a particular month and next month his class might change. Now what I want to do is for each ID get the number of months it has been under a particular class and also the latest class under which it falls. Something like below:
ID Class_A Class_B Class_D Other Latest_Class
1 2 3 4 0 B
2 12 0 0 0 D
How do I achieve this in python. Can someone please help me with this? Also , since the real dataset is huge and manually verifying is not possible, how can I get a list of ID's which fall under more than 1 class?