Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from countrynames import to_code_3
emissions_transfers_csv = root / "data/emissions-transfers.csv"
# Emissions transfers
emissions_transfers = pd.read_excel(
excel_national,
sheet_name="Emissions Transfers",
skiprows=8,
index_col=0
)
emissions_transfers.index.name = "Year"
emissions_transfers = emissions_transfers.T
emissions_transfers.index.rename("Name", inplace=True)
emissions_transfers["Code"] = [to_code_3(i) or i
for i in emissions_transfers.index]
emissions_transfers = emissions_transfers.reset_index().drop(
"Name", axis=1)
emissions_transfers = pd.melt(
emissions_transfers,
id_vars="Code",
var_name="Year",
value_name="Emissions-Transfers"
)
emissions_transfers.sort_values(["Code", "Year"], inplace=True)
emissions_transfers.dropna(inplace=True)
# Territorial GCB emissions
territorial_gcb = pd.read_excel(
excel_national,
sheet_name="Territorial Emissions",
skiprows=16,
index_col=0,
usecols="A:HW"
)
territorial_gcb.index.name = "Year"
territorial_gcb = territorial_gcb.T
territorial_gcb.index.rename("Name", inplace=True)
territorial_gcb["Code"] = [to_code_3(i) or i for i in territorial_gcb.index]
territorial_gcb = territorial_gcb.reset_index().drop("Name", axis=1)
territorial_gcb = pd.melt(
territorial_gcb,
id_vars='Code',
var_name="Year",
value_name="Emissions"
)
territorial_gcb.sort_values(["Code", "Year"], inplace=True)
territorial_gcb['Source'] = np.where(
territorial_gcb.Year < 2017, "CDIAC", "BP")
territorial_cdiac_csv = root / "data/territorial-emissions-cdiac.csv"
# Territorial CDIAC emissions
territorial_cdiac = pd.read_excel(
excel_national,
sheet_name="Territorial Emissions CDIAC",
skiprows=13,
index_col=0
)
territorial_cdiac.index.name = "Year"
territorial_cdiac = territorial_cdiac.T
territorial_cdiac.index.rename("Name", inplace=True)
territorial_cdiac["Code"] = [to_code_3(i) or i
for i in territorial_cdiac.index]
territorial_cdiac = territorial_cdiac.reset_index().drop("Name", axis=1)
territorial_cdiac = pd.melt(
territorial_cdiac,
id_vars="Code",
var_name="Year",
value_name="Emissions"
)
territorial_cdiac.dropna(inplace=True)
territorial_cdiac.sort_values(["Code", "Year"], inplace=True)
territorial_cdiac.to_csv(
from countrynames import to_code_3
consumption_emissions_csv = root / "data/consumption-emissions.csv"
# Consumption emissions
consumption_emissions = pd.read_excel(
excel_national,
sheet_name="Consumption Emissions",
skiprows=8,
index_col=0
)
consumption_emissions.index.name = "Year"
consumption_emissions = consumption_emissions.T
consumption_emissions.index.rename("Name", inplace=True)
consumption_emissions["Code"] = [to_code_3(i) or i
for i in consumption_emissions.index]
consumption_emissions = consumption_emissions.reset_index().drop(
"Name", axis=1)
consumption_emissions = pd.melt(
consumption_emissions,
id_vars="Code",
var_name="Year",
value_name="Consumption-Emissions"
)
consumption_emissions.sort_values(["Code", "Year"], inplace=True)
consumption_emissions.dropna(inplace=True)