IN大熊猫,我想减去两个连续的行并保存在第一行中

问题描述 投票:1回答:1

我有一个格式为226列的数据框:

**W    X    Y    Z.....**
  a    b    c    d.....
  e    f    g    h.....    

我想通过以下方式减去列Y和Z:

**W      X      Y          Z.....**
  a    (b-c)  (c-d)  (d-nextvalue).....
  e    (f-g)  (g-h)  (h-nextvalue).....   

我该如何去做?我是python的菜鸟,在此先感谢

python pandas dataframe diff
1个回答
2
投票

使用DataFrame.diff,并在必要时通过DataFrame.diff将第一列转换为索引:

DataFrame.set_index
© www.soinside.com 2019 - 2024. All rights reserved.