Whats your python code atm?
I'm still a really novice... but I tried the following. May be it will help or offer a different way
I'm still a really novice... but I tried the following. May be it will help or offer a different way
import pandas as pd sample_data = [ ('sample001a.com', -12, 'sample002b.com', -16, 'sample002c.com', -18), ('sample002a.com', -14, 'sample003b.com', -16, 'sample004c.com', -22), ('sample003a.com', -16, 'sample004b.com', -20, 'sample005c.com', -16), ('sample004a.com', -18, 'sample005b.com', -14), ('sample005a.com', -12), ] tdf = pd.DataFrame(sample_data,columns=['sample','total','s1','t1','s2','t2']) df = tdf[['sample','total']] a = tdf[['s1','t1']].rename(columns={'s1':'sample','t1':'total'}) df = df.append(a) a = tdf[['s2','t2']].rename(columns={'s1':'sample','t1':'total'}) df = df.append(a) df.groupby(by='sample',sort=True).sum()