Created
July 5, 2020 20:56
-
-
Save dkmehrmann/f1e12d46c37763c6a0e19c1e510fec36 to your computer and use it in GitHub Desktop.
Code to compare GDP to CO2 Levels since the year 0 AD
This file contains 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
import matplotlib.pyplot as plt | |
import numpy as np | |
import pandas as pd | |
gdp_ = 'http://www.ggdc.net/MADDISON/Historical_Statistics/vertical-file_02-2010.xls' | |
gdp = pd.read_excel(gdp_, sheet_name='PerCapita GDP', header =2, usecols=[0, 182], names=['year', 'GlobalGDPPerCapita']).dropna() | |
gdp.year = gdp.year.astype(int) | |
co2_ = 'ftp://data.iac.ethz.ch/CMIP6/input4MIPs/UoM/GHGConc/CMIP/yr/atmos/UoM-CMIP-1-1-0/GHGConc/gr3-GMNHSH/v20160701/mole_fraction_of_carbon_dioxide_in_air_input4MIPs_GHGConcentrations_CMIP_UoM-CMIP-1-1-0_gr3-GMNHSH_0000-2014.csv' | |
co2 = pd.read_csv(co2_) | |
df = gdp.merge(co2, on='year', how='inner').set_index('year') | |
df['LOG GDP Per Capita'] = np.log(df['GlobalGDPPerCapita']) | |
df = df/df.loc[1] * 100 | |
df = df.reset_index() | |
fig, ax = plt.subplots(figsize=(10,5)) | |
ax.plot(df['year'], df['LOG GDP Per Capita'], label='Log Global GDP Per Capita') | |
ax.plot(df['year'], df['data_mean_global'], label='Global C02 Levels') | |
plt.legend(frameon=False, ncol=2, loc='upper center') | |
plt.xlabel('Year') | |
plt.ylabel('Indexed to Year 1 AD = 100') | |
plt.title('Global Economic Output and CO2 Levels', y = 1.05, size=16, loc='left') | |
ax.spines['top'].set_color('none') | |
ax.spines['right'].set_color('none') | |
ax.text(x=0, y=-0.2, s='Sources: IAC Switzerland and Angus Maddison', transform = ax.transAxes) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment