Skip to content

Instantly share code, notes, and snippets.

@ccerv1
Created February 23, 2019 13:43
Show Gist options
  • Select an option

  • Save ccerv1/e45be7da13ca910297a828531fae9db4 to your computer and use it in GitHub Desktop.

Select an option

Save ccerv1/e45be7da13ca910297a828531fae9db4 to your computer and use it in GitHub Desktop.
Apply a CAGR function to each country's production series
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