如何在python中将分类行转换为列

如何在python中将分类行转换为列,python,pandas,Python,Pandas,我有一个带有两列('X','Y')的数据框,数据框如下所示 X Y 0 id: 35252916702903 1 userName: IAMAdmin 2 eventTime

我有一个带有两列('X','Y')的数据框,数据框如下所示

           X                                 Y
0               id:                                35252916702903
1         userName:                                           IAMAdmin
2         eventTime                               2020-02-04T05:42:16Z
3         awsRegion                                          us-east-1
4   sourceIPAddress                                     203.99.xx.xx
5               id:                                3525291679
6         userName:                                           IAMAdmin
7         eventTime                               2020-02-04T05:41:58Z
8         awsRegion                                          us-east-1
9   sourceIPAddress                                     203.99.xx.xx
10              id:                               3525288310411
11        userName:                                      EC2FullAccess
12        eventTime                               2020-02-04T05:18:39Z
13        awsRegion                                          us-east-1
14  sourceIPAddress                                       34.229.xx.xx
       id           userName               eventTime                    awsRegion     sourceIPAddress

35252916702         IAMAdmin              2020-02-04T05:42:16Z          us-east-1      203.99.xx.xx
352529167           IAMAdmin              2020-02-04T05:41:58Z          us-east-1       34.229.xx.xx
 ....
 ...
现在我想让上面的数据框看起来像这样

           X                                 Y
0               id:                                35252916702903
1         userName:                                           IAMAdmin
2         eventTime                               2020-02-04T05:42:16Z
3         awsRegion                                          us-east-1
4   sourceIPAddress                                     203.99.xx.xx
5               id:                                3525291679
6         userName:                                           IAMAdmin
7         eventTime                               2020-02-04T05:41:58Z
8         awsRegion                                          us-east-1
9   sourceIPAddress                                     203.99.xx.xx
10              id:                               3525288310411
11        userName:                                      EC2FullAccess
12        eventTime                               2020-02-04T05:18:39Z
13        awsRegion                                          us-east-1
14  sourceIPAddress                                       34.229.xx.xx
       id           userName               eventTime                    awsRegion     sourceIPAddress

35252916702         IAMAdmin              2020-02-04T05:42:16Z          us-east-1      203.99.xx.xx
352529167           IAMAdmin              2020-02-04T05:41:58Z          us-east-1       34.229.xx.xx
 ....
 ...
“x”列中的分类值应作为唯一列,其值应作为观察值

如何使用熊猫进行此操作?

与以下设备一起使用:

输出:

              id:      userName:             eventTime  awsRegion  \
0  35252916702903       IAMAdmin  2020-02-04T05:42:16Z  us-east-1   
1      3525291679       IAMAdmin  2020-02-04T05:41:58Z  us-east-1   
2   3525288310411  EC2FullAccess  2020-02-04T05:18:39Z  us-east-1   

  sourceIPAddress  
0    203.99.xx.xx  
1    203.99.xx.xx  
2    34.229.xx.xx