Python 使用dataframe将唯一值转换为列名

Python 使用dataframe将唯一值转换为列名,python,pandas,pandas-groupby,Python,Pandas,Pandas Groupby,我有以下提到的格式的熊猫数据帧 input_df : gw_mac mac val status 0 AC233FC01403 AC233F264A4C -21 Outwards 1 AC233FC015F6 AC233F264A4C -37 Outwards 2 AC233FC01403 AC233F264A4C -20 Outwards 3 AC233FC015F6 AC233F264A4C -37

我有以下提到的格式的熊猫数据帧

input_df :
    gw_mac        mac          val    status 
0   AC233FC01403  AC233F264A4C -21    Outwards
1   AC233FC015F6  AC233F264A4C -37    Outwards
2   AC233FC01403  AC233F264A4C -20    Outwards
3   AC233FC015F6  AC233F264A4C -37    Outwards
4   AC233FC01403  AC233F264A4C -29    Outwards
5   AC233FC015F6  AC233F264A4C -39    Outwards
6   AC233FC01403  AC233F264A4C -37    Outwards
7   AC233FC015F6  AC233F264A4C -37    Outwards
8   AC233FC01403  AC233F264A4C -22    Outwards
9   AC233FC015F6  AC233F264A4C -37    Outwards
10  AC233FC015F6  AC233F264A4C -37    Outwards
我需要转换相同的,就像下面的一样

output_df:
    AC233FC01403  AC233FC015F6  mac            status    
1   -21           -37           AC233F264A4C   Outwards  
2   -20           -37           AC233F264A4C   Outwards
3   -29           -39           AC233F264A4C   Outwards
4   -37           -37           AC233F264A4C   Outwards
5   -22           -37           AC233F264A4C   Outwards
6    0            -37           AC233F264A4C   Outwards
用于带有和的新
计数器
列:

如果列的顺序很重要:

df = df[df.columns[2:].tolist() + df.columns[:2].tolist()]
print (df)
   AC233FC01403  AC233FC015F6           mac    status
0           -21           -37  AC233F264A4C  Outwards
1           -20           -37  AC233F264A4C  Outwards
2           -29           -39  AC233F264A4C  Outwards
3           -37           -37  AC233F264A4C  Outwards
4           -22           -37  AC233F264A4C  Outwards
5             0           -37  AC233F264A4C  Outwards

你能展示一下你有什么吗tried@jezrael,您提供的链接包含唯一的行值,如row0、row2、row4,而在我的示例中,“mac”列下的所有值都是相同的。
df = df[df.columns[2:].tolist() + df.columns[:2].tolist()]
print (df)
   AC233FC01403  AC233FC015F6           mac    status
0           -21           -37  AC233F264A4C  Outwards
1           -20           -37  AC233F264A4C  Outwards
2           -29           -39  AC233F264A4C  Outwards
3           -37           -37  AC233F264A4C  Outwards
4           -22           -37  AC233F264A4C  Outwards
5             0           -37  AC233F264A4C  Outwards