0

Required task

I have the following DataFrame and I want to get the data to simply have the unique count changes of the Rating for each id

             date  Rating  id
0      2019-12-31    A      1
1      2019-12-31    B      2
2      2019-11-30    A      1
3      2019-11-30    A      2
4      2019-10-31    B      1
5      2019-10-31    A      2
6      2019-09-30    C      1
7      2019-09-30    A      2
8      2019-08-31    B      1
9      2019-08-31    B      2

Goal

id   Rating   Unique Count
1      A        1
1      B        2
1      C        1
2      A        1
2      B        2

The above DataFrame is simply an example, I am not exactly sure how it would look it pandas. Any help would be awesome!

oceanbeach96
  • 604
  • 9
  • 19
  • 1
    See here: https://stackoverflow.com/questions/38309729/count-unique-values-with-pandas-per-groups – Carsten Mar 24 '20 at 08:15
  • It seems dupe, if not, can you explain more? e.g first 2 rows of output, also last row `2 A 1` and 4th row `2 A 1` are same? – jezrael Mar 24 '20 at 08:20
  • The link above does not achieve the desired output. For example, for id 1, Rating starts at A, then goes to B, then C, then back to B. The link would only count B once. I am interested in it increasing the count for the rating if it changes. E.g. B would be 2, not 1 – oceanbeach96 Mar 24 '20 at 08:48

0 Answers0