0

gaess, I Want to subtract the previous values and next value (previous - next) in one columns on Python dataframe. The example and the output like this :

This is the one column dataframe:

  | Gross_reserve|
  | ------------ |
0 | 1.202.170,21 | 
1 | 1.190.721,39 | 
2 | 1.179.354,33 | 
3 | 1.131.377,18 | 
4 |     ...      |   

And then the output i want is make a new columns called "cf_res_g" with the value like this :

  | Gross_reserve| cf_res_g |
  | ------------ | -------- |
0 | 1.202.170,21 | 11.448,82|
1 | 1.190.721,39 | 11.367,06|
2 | 1.179.354,33 | 47.997,16|
3 | 1.131.377,18 |  ...     |
4 |     ...      |  ...     |

so, if we do calculation is like this: index[0] - index[1], index[1] - index[2], etc

  • 2
    The input and the output looks very similar, can you please validate that they are correct? – Tom Ron Jan 04 '23 at 11:28
  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jan 04 '23 at 11:30
  • @TomRon sorry i got error when i want to write the problem, i already fix it. Thankyou – Zefanya Simijaya Jan 04 '23 at 11:42

1 Answers1

-1

I think you are asking for a diff: pandas.DataFrame.diff.

Mahmoud
  • 9,729
  • 1
  • 36
  • 47