重塑熊猫数据框:每两行在一起

时间:2020-05-26 13:38:05

标签: python pandas dataframe

我有一个用于统计足球比赛数据的数据框,每两排(主队和客队)每场比赛 如下:

date       HorA League  Teams   statistic 1     statistic 2     statistic 3
21/02/2020  H   ARG     Team1   20               10              100
21/02/2020  A   ARG     Team2   20               90              20
22/02/2020  H   MEX     Team3   30               15              5
22/02/2020  A   MEX     Team4   80               10              17
26/02/2020  H   ARG     Team5   10               7               3
26/02/2020  A   ARG     Team6   5                80              40
29/02/2020  H   USA     Team7   90               5               8
29/02/2020  A   USA     Team8   7                100             15

(第2列“ HorA”:H =主队,A =客队)

我想重塑形状,并每行放置每局游戏,如下表所示:

date           League   H_Teams     A_Team  H_stat_1    A_stat_1    H_stat_2    A_stat_2    H_stat_3    A_stat_3
21/02/2020      ARG     Team1       Team2   20          20          10          90          100         20
22/02/2020      MEX     Team3       Team4   30          80          15          10          5           17
26/02/2020      ARG     Team5       Team6   10          5           7           80          3           40
29/02/2020      USA     Team7       Team8   90          7           5           100         8           15

0 个答案:

没有答案