lundi 18 juillet 2016

How to merge two tables and transpose rows to columns

I have these two tables:

T1

id  x       y
8   42      1.9
9   30      1.9

T2

id  signal
8   55
8   56  
8   59
9   57
9   58  
9   60

The goal is to get the new table T3:

id  x       y       s1      s2      s3
8   42      1.9     55      56      58
9   30      1.9     57      58      60

If I do this operation, then it only performs merging without transposing:

pd.merge(T1, T2, on=['id'])

How to create columns s1, s2 and s3, each corresponding to a row (the number of rows per id is always fixed and equal to 3)?

Aucun commentaire:

Enregistrer un commentaire