📜  pd.explode - 任何代码示例

📅  最后修改于: 2022-03-11 15:00:15.200000             🧑  作者: Mango

代码示例1
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]