Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop non string entries in country column of CO2_emissions data in prepare_transport_data_input #1166

Merged
merged 7 commits into from
Nov 12, 2024
Merged
2 changes: 2 additions & 0 deletions doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ E.g. if a new rule becomes available describe how to use it `make test` and in o

* Fix bugs in `prepare_sector_network.py` related to links with H2 buses and bug of re-addition of H2 and battery carriers in present `PR #1145 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/1145>`__

* Drop entries that contain non-string elements in country column of `CO2_emissions_csv` data in `prepare_transport_data_input.py` script `PR #1166 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/1166>`_

PyPSA-Earth 0.4.1
=================

Expand Down
9 changes: 6 additions & 3 deletions scripts/prepare_transport_data_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,17 @@ def download_CO2_emissions():
# Add ISO2 country code for each country
CO2_emissions = CO2_emissions.rename(columns={"Country Name": "Country"})
cc = coco.CountryConverter()
Country = pd.Series(CO2_emissions["Country"])
CO2_emissions["country"] = cc.pandas_convert(
series=Country, to="ISO2", not_found="not found"
CO2_emissions.loc[:, "country"] = cc.pandas_convert(
series=CO2_emissions["Country"], to="ISO2", not_found="not found"
)

# Drop region names that have no ISO2:
CO2_emissions = CO2_emissions[CO2_emissions.country != "not found"]

# Drop region names where country column contains list of countries
davide-f marked this conversation as resolved.
Show resolved Hide resolved
CO2_emissions = CO2_emissions[
CO2_emissions.country.apply(lambda x: isinstance(x, str))
]
return CO2_emissions


Expand Down
Loading