You can create an inverse dictionary and map:
d = {'personal_info': ['PERSON','LOCATION','PHONE_NUMBER','EMAIL_ADDRESS','PASSPORT','SSN','DRIVER_LICENSE'],
'finance':['CREDIT_CARD','BANK_NUMBER','ITIN','IBAN_CODE'],
'info': ['NHS'],
'network':['IP_ADDRESS','DOMAIN_NAME'],
'others':['CRYPTO','DATE_TIME','NRP']
}
d_inv = {x:k for k, v in d.items() for x in v}
(df['Counts'].groupby(df['PII'].map(d_inv)).sum()
.rename_axis('Cluster names') # rename to match output
.reset_index(name='Total count')
)
Output:
Cluster names Total count
0 finance 97
1 info 0
2 network 140
3 others 86
4 personal_info 460
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…