Python - Pandas - Unroll / Remove Cumulative Sum

前端 未结 2 857
长情又很酷
长情又很酷 2021-01-06 00:45

I have a data frame like the following (specific data below, this is generic). The no gives me a cumulative sum:

                 no
name day           
Jack         


        
2条回答
  •  礼貌的吻别
    2021-01-06 01:17

    Here's a method based on zip. It creates two series, the 2nd being offset by 1, and subtracts the difference between the two.

    [n-nn for n,nn in zip(df['No'],df['No'][1:]+[0])]
    

提交回复
热议问题