I have the following dataframe
#Example for Stackoverflow
df = pd.DataFrame({'Ticker': ['AAPL', 'MSFT', 'IBM'],
'totalRevenue_ttm': [386017000000, 192557000000, 50608000000],
'revenues_2021': [365817000000, 168088000000, 57351000000],
'revenues_2020': [274515000000, 143015000000, 55179000000],
'revenues_2019': [260174000000, 125843000000, 57714000000],
'revenues_2018': [265595000000, 110360000000, 79591000000]})
I would like to calculate the growth rates of sales for 2021, 2020 and 2019.
If I use the following code, I get the growth rate for 2021
col=2
df[str(revenues.columns[col]) + "_Growth"]=(df.iloc[:, col]-revenues.iloc[:, col+1])/df.iloc[:, col+1]
df
How can I iterate over the columns, so I can calculate also revenues_2020_Growth and revenues_2019_Growth
thank your help, I very much appreciate it.
