I have many groups such as:
BB = ['AA', 'BB', 'CC']
BR = ['LL', 'PP', 'KK']
I have a different column:
| df.Sig |
|---|
| 'AA' |
| 'BB' |
| 'CC' |
| 'LL' |
| 'PP' |
| 'KK' |
I want to create a different column which represents the group:
| df.Sig | Group |
|---|---|
| 'AA' | 'BB' |
| 'BB' | 'BB' |
| 'CC' | 'BB' |
| 'LL' | 'BR' |
| 'PP' | 'BR' |
| 'KK' | 'BR' |
I am currently using:
df.iloc[df['Sig'].isin(BB), 'Group'] = 'BB'
This is not the most efficient, nor is it fastest, way to do this.
Is there any other one liner that I can use to achieve the same, but faster?