<jupyter_start><jupyter_text>Turkey: Merging attributes with NUTS2 Nomenclature of Territorial Units for Statistics or NUTS (French: Nomenclature des unités territoriales statistiques) is a geocode standard for referencing the subdivisions of countries for statistical purposes. [Wikipedia](https://en.wikipedia.org/wiki/Nomenclature_of_Territorial_Units_for_Statistics)This notebook combines data generated in Stata with standart NUTS2 region. The regions can be downloaded [here](https://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/administrative-units-statistical-units/nuts).<jupyter_code>attributes = pd.io.stata.read_stata("../data/nuts2_attributes.dta")
#coordinates = pd.io.stata.read_stata("../data/nuts2_coordinates.dta")
attributes.columns<jupyter_output><empty_output><jupyter_text>Let's now load the NUTS2 regions in WGS 84 (EPSG 4326),<jupyter_code>NUTS = gpd.read_file("../data/ref-nuts-2021-01m.geojson/NUTS_RG_01M_2021_4326_LEVL_2.geojson")<jupyter_output><empty_output><jupyter_text>Let's filter `TR`,<jupyter_code>NUTS = NUTS[NUTS["CNTR_CODE"] == "TR"]<jupyter_output><empty_output><jupyter_text>In fact, we see 26 regions (as expected),<jupyter_code>len(NUTS)<jupyter_output><empty_output><jupyter_text>Now, let's merge with `attributes` into a `pandas.DataFrame`,<jupyter_code>df = pd.merge(attributes, NUTS[["NUTS_ID", "geometry"]], left_on="nuts2_regions", right_on="NUTS_ID")<jupyter_output><empty_output><jupyter_text>Finally, into a `geopandas.GeoDataFrame`,<jupyter_code>gdf = gpd.GeoDataFrame(df)
gdf.plot()<jupyter_output><empty_output><jupyter_text>And exporting,<jupyter_code># remove duplicated columns
gdf.drop("NUTS_ID", axis=1, inplace=True)
gdf.to_file("../data/attributes.shp")
gdf.to_file("../data/attributes.geojson", driver="GeoJSON")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13333333333333333, 'fraction_numerical': 0.017630853994490357, 'mean_word_length': 9.145251396648044, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '424824', 'license': 'MIT', 'n_tokens_mistral': 722, 'n_tokens_neox': 679, 'n_words': 102, 'path': 'notebooks/tur-merging-attributes-with-nuts2.ipynb', 'repo_name': 'worldbank/Turkey_Urbanization', 'size': '1815'}