Created
February 23, 2019 13:43
-
-
Save ccerv1/e45be7da13ca910297a828531fae9db4 to your computer and use it in GitHub Desktop.
Apply a CAGR function to each country's production series
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def cagr(series): | |
| start_val = series.iloc[0] | |
| if not start_val: | |
| return None | |
| end_val = series.iloc[-1] | |
| num_vals = len(series) | |
| CAGR = (end_val/start_val)**(1/num_vals)-1 | |
| return CAGR | |
| world_production['CAGR'] = world_production.apply(cagr, axis=1) | |
| world_production.dropna(inplace=True) | |
| world_production = world_production[world_production.CAGR != -1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment