diff --git a/doc/release_notes.rst b/doc/release_notes.rst index 5cc3422c0..3f1318334 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -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 `__ +* Drop entries that contain non-string elements in country column of `CO2_emissions_csv` data in `prepare_transport_data_input.py` script `PR #1166 `_ + PyPSA-Earth 0.4.1 ================= diff --git a/scripts/prepare_transport_data_input.py b/scripts/prepare_transport_data_input.py index a15608adc..d932d1174 100644 --- a/scripts/prepare_transport_data_input.py +++ b/scripts/prepare_transport_data_input.py @@ -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