Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

pd.explode

stacked = df.stack().explode().reset_index()
stacked["uid"] = stacked.groupby(["level_0", "level_1"]).cumcount()
output = stacked.pivot(["level_0", "uid"], "level_1", 0).reset_index(drop=True).rename_axis(None, axis=1)

>>> output

        TGR1 TGR2 TGR3
0          1    5    4
1          7    8    1
2          5    1    8
3          9    1    3
4          1    7    2
..       ...  ...  ...
69         4    8    2
70         5    4    2
71         5    1    4
72         2    6    1
73         1    8    7

[74 rows x 3 columns]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged:
ADD COMMENT
Topic
Name
1+5 =