我有一个pandas数据框,设置如下:
Date Name A B C
09-01-10 Rose 11 2 5
09-01-11 Rose 12 6 7
09-01-12 Rose 9 7 14
09-01-10 Emma 20 70 24
09-01-11 Emma 19 74 19
我希望将A,B和C列的值向上移动1天,以便新数据框看起来像这样:
Date Name A B C
09-01-10 Rose 12 6 7
09-01-11 Rose 9 7 14
09-01-12 Rose NA NA NA
09-01-10 Emma 19 74 19
09-01-11 Emma NA NA NA
我试过了:
data= data.groupby(["Date","Name"]).sum()
data = data.shift(-1)
它最终看起来像这样,这是不正确的:
Date Name A B C
09-01-10 Rose 12 6 7
09-01-11 Rose 9 7 14
09-01-12 Rose 20 70 14
09-01-10 Emma 19 74 19
09-01-11 Emma NA NA NA