Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- df
- id list_of_tuples
- 0 abc-123 [('cat',100,'xyz-123'),('cat',96,'uvw-456')]
- 1 def-456 [('dog',98,'rst-789'),('dog',97,'opq-123'),('dog',95,'lmn-123')]
- 2 ghi-789 [('tree',100,'ijk-123')]
- df_new
- id val_1 val_2 val_3
- 0 abc-123 cat 100 xyz-123
- 1 abc-123 cat 96 uvw-456
- 2 def-456 dog 98 rst-789
- 3 def-456 dog 97 opq-123
- 4 def-456 dog 95 lmn-123
- 5 ghi-789 tree 100 ijk-123
- df_new = pd.DataFrame(list(chain.from_iterable(df.matches)),columns=['val_1','val_2','val_3']).reset_index(drop=True)
- df_new['id'] = np.repeat(df.id.values, df['list_of_tuples'].str.len())
Add Comment
Please, Sign In to add comment