0

I have a df that shows Dates and Values and I would like to calculate the percent change or percent increase between rows - showing the difference between the change from 10/07/2020 to 10/08/2020

   Date           Value
    
   10/08/2020     30
   10/07/2020     30
   10/06/2020     30
   10/05/2020     30
   10/04/2020     30

Desired Result

   Date           Value     PercentIncrease 
    
   10/08/2020     30        0%
   10/07/2020     30        0%
   10/06/2020     30        0%
   10/05/2020     30        0%
   10/04/2020     30        0%

This is what I am doing:

(df['Delta'] / df['Delta'].shift(1) - 1).fillna(0)

Is there a way to show the percent sign too?

Lynn
  • 4,292
  • 5
  • 21
  • 44

1 Answers1

1

If you want a string with %:

df['PctIncrease'] = [f'{x:.2%}' for x in (df['Value'].div(df['Value'].shift(1)) - 1).fillna(0)]
Quang Hoang
  • 146,074
  • 10
  • 56
  • 74