I have a dataframe that looks conceptually as follows:
df = pd.DataFrame({
"a": [1, 1, 1, 2, 2,3],
"b": ["a", "a", "c", "a", "d","a"],
"c": ["2", "3", "4", "2", "3","2"]
})
a b c
0 1 'a' '2'
1 1 'a' '3'
2 1 'c' '4'
3 2 'a' '2'
4 2 'd' '3'
5 3 'a' '2'
For each group of aI need to count unique values (b,c)before that.
So, in this example, ouptut should be [3,4,4].
(because in group 1 there are 3 unique pairs (b,c), and in groups 1 and 2 there are 4 unique values (b,c), and in groups 1 and 2 and 3 together there are only 4 unique (b,c)values.
I tried using expandingwith groupbyand nunique, but I could not understand the syntax.
Any help would be appreciated!