首页 > 解决方案 > Python DataFrame:Pandas groupby 行到列?

问题描述

我正在尝试将多行相同行的列

df

            name        subject
    0     marcus         math
    1     marcus         chemistry
    2     marcus         physics
    3     bruno          math
    4     bruno          physics
    5     cavani         math

最终df

            name        subject1    subject2    subject3
    0     marcus         math       chemistry    physics
    1     bruno          math       physics
    2     cavani         math


    Columns names can also be subject_x,subject_y,subject_z

标签: pythonpandasdataframenumpy

解决方案


推荐阅读