我有一个熊猫数据框,如下所示:
# Date Name RG
#-----------------------------------
# 1: 2013-04-25 NameA 1
# 2: 2013-04-25 NameB 3
# 3: 2013-04-25 NameC 1
# 4: 2013-04-25 NameD 2
# 5: 2013-04-25 NameE 1
# ---
# 13379: 2020-02-13 NameA 3
# 13380: 2020-02-13 NameB 1
# 13381: 2020-02-13 NameC 4
# 13382: 2020-02-13 NameD 1
# 13383: 2020-02-13 NameE 1
我想透视表并使用 Name 列作为索引。每个日期现在都显示为一个单独的列,因此,对于每个名称索引,在过去六个月中对 RG 进行汇总,例如RG 2020-02-06中NameA的值是通过将2019-08-07和2020-02-06之间的NameA的所有RG值相加而获得的。例如:
# Name 2013-04-25 2013-04-31 2013-05-07 --- 2020-02-06 2020-02-13
#--------------------------------------------------------------------------------------------------
# 1: NameA 1 2 3 7 23
# 2: NameB 3 3 6 15 21
# 3: NameC 1 4 5 16 24
# 4: NameD 2 2 7 19 40
# 5: NameE 1 4 9 15 21
# ---
# 276: NameDE 3 4 6 15 22
# 277: NameDF 1 4 6 17 22
# 278: NameDG 4 8 9 11 23
# 279: NameDH 2 3 5 19 24
# 280: NameDI 1 4 6 18 20
如何使用熊猫编写代码?