[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
8d09e38627
commit
dadc372ecd
@ -96,12 +96,15 @@ def prepare_hotmaps_database(regions):
|
|||||||
# the .sjoin can lead to duplicates if a geom is in two regions
|
# the .sjoin can lead to duplicates if a geom is in two regions
|
||||||
if gdf.index.duplicated().any():
|
if gdf.index.duplicated().any():
|
||||||
import pycountry
|
import pycountry
|
||||||
|
|
||||||
# get all duplicated entries
|
# get all duplicated entries
|
||||||
duplicated_i = gdf.index[gdf.index.duplicated()]
|
duplicated_i = gdf.index[gdf.index.duplicated()]
|
||||||
# convert from raw data country name to iso-2-code
|
# convert from raw data country name to iso-2-code
|
||||||
s = df.loc[duplicated_i, "Country"].apply(lambda x: pycountry.countries.lookup(x).alpha_2)
|
s = df.loc[duplicated_i, "Country"].apply(
|
||||||
|
lambda x: pycountry.countries.lookup(x).alpha_2
|
||||||
|
)
|
||||||
# Get a boolean mask where gdf's country column matches s's values for the same index
|
# Get a boolean mask where gdf's country column matches s's values for the same index
|
||||||
mask = gdf['country'] == gdf.index.map(s)
|
mask = gdf["country"] == gdf.index.map(s)
|
||||||
# Filter gdf using the mask
|
# Filter gdf using the mask
|
||||||
gdf_filtered = gdf[mask]
|
gdf_filtered = gdf[mask]
|
||||||
# concat not duplicated and filtered gdf
|
# concat not duplicated and filtered gdf
|
||||||
|
Loading…
Reference in New Issue
Block a user