让我们使用
set_index,
groupby,
cumcount,和
unstack:
df.set_index(df.groupby(level=0).cumcount(), append=True)[0].unstack()
输出:
0 10 a b1 c d

让我们使用
set_index,
groupby,
cumcount,和
unstack:
df.set_index(df.groupby(level=0).cumcount(), append=True)[0].unstack()
输出:
0 10 a b1 c d