Это melt
:
df.melt(id_vars=['Operator id', 'CountryID']).drop('variable', 1).dropna()
Выход:
Operator id CountryID value
0 john.smith 376.0 jake.sha.human
1 john.wayne 826.0 sambaser@fake.com
2 mike.evans 840.0 ardenn@fake.com
3 sarah.wagner 356.0 nathan@fake.com
4 two.chains 784.0 AR@fake.com
7 mike.evans 840.0 isabellac@fake.com
9 two.chains 784.0 hr@fake.com
12 mike.evans 840.0 sam.cha
Или stack
:
(df.set_index(['Operator id', 'CountryID'])
.stack()
.reset_index(level=-1, drop=True)
.reset_index(name='TransCol')
)
Выход:
Operator id CountryID TransCol
0 john.smith 376.0 jake.sha.human
1 john.wayne 826.0 sambaser@fake.com
2 mike.evans 840.0 ardenn@fake.com
3 mike.evans 840.0 isabellac@fake.com
4 mike.evans 840.0 sam.cha
5 sarah.wagner 356.0 nathan@fake.com
6 two.chains 784.0 AR@fake.com
7 two.chains 784.0 hr@fake.com