我在熊猫中有一个奇怪的原始数据框,看起来像:
class year period type info valuebasic value1 value2 value3... value16
A 2019 16 A bla 10 1 0 0 2
A 2019 32 A bla 20 0 1 1 1
...
A 2021 16 A bla 30 30 1 2 1
...
B 2019 16 A bla 1 1 1 1 1
我想计算每个学年和每个时段的累积szn fir值列,这样我就得到了17-32等时段的累积szn fir值,其结果是以下数据帧:
class year period type info value
A 2019 16 A bla 10
A 2019 17 A bla 11 (10+1)
A 2019 18 A bla 11 (10+1+0)
....
A 2019 32 A bla 20 (10+1+0+0+...+2)
A 2019 32 A bla 20
...
A 2021 16 A bla 30
.....
B 2019 16 A bla 1
....
B 2019 32 A bla 24 (1+1+...+1)
使用^{} 与^{} 进行unpivot:
替代解决方案:
要修复原始列
value
,请使用:相关问题 更多 >
编程相关推荐