Skip to content

Commit

Permalink
Drop non string entries in country column of CO2_emissions data in `p…
Browse files Browse the repository at this point in the history
…repare_transport_data_input` (#1166)

* drop list entries in country column of CO2_emissions data in prepare_transport_data_input

* add release notes

* remove redefining Series

* Update scripts/prepare_transport_data_input.py

* no axis specification for series
  • Loading branch information
yerbol-akhmetov authored Nov 12, 2024
1 parent 9a50694 commit 2c7cbdb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
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
CO2_emissions = CO2_emissions[
CO2_emissions.country.apply(lambda x: isinstance(x, str))
]
return CO2_emissions


Expand Down

0 comments on commit 2c7cbdb

Please sign in to comment.