I have a dataframse such as
Groups SP Letters
G1 SP1 A
G1 SP1 Z
G1 SP1 A
G1 SP2 X
G1 SP3 X
G1 SP4 B
G2 SP2 A
G2 SP5 B
G2 SP3 X
G2 SP23 A
and I would like to add a column (Nb_column) which would be the count of unique SP value within each Groups but where Letters are in a list the_list=['A','B']
here I should then get:
Groups SP Letters Nb_column
G1 SP1 A 2
G1 SP1 Z 2
G1 SP1 A 2
G1 SP2 X 2
G1 SP3 X 2
G1 SP4 B 2
G2 SP2 A 3
G2 SP5 B 3
G2 SP3 X 3
G2 SP23 A 3
Where
- there are 2
SP(SP1,SP4) with aLettersinthe_listfor the G1. And - there are 3
SP(SP2,SP5 and SP23) with aLettersinthe_listfor the G2.
Does someone have an idea in pandas please ?