File size: 1,025 Bytes
908b9a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import pandas as pd
import os

MISSING_ENRICHED = os.path.join("data", "missing_enriched.csv")
CITIES_ENRICHED = os.path.join("data", "cities_enriched_final.csv")
CITIES_ENRICHED_MANUALLY = os.path.join("data", "cities_enriched_manually.csv")


def merge_missing_coord(df, missing):
    for row in df.itertuples():
        if row.Kommune in missing["Kommune"].values:
            new_geo = missing[missing["Kommune"] == row.Kommune].iloc[0].Geometry
            df.at[row.Index, "Geometry"] = new_geo
    return df


cities = pd.read_csv(CITIES_ENRICHED)
if "_1" in cities.columns:
    cities.drop(columns=["_1"], inplace=True)

cities_final = merge_missing_coord(
    pd.read_csv(CITIES_ENRICHED), pd.read_csv(MISSING_ENRICHED)
)

cities_final.to_csv(CITIES_ENRICHED_MANUALLY, index=False)
still_missing = cities_final[
    cities_final["Geometry"].apply(lambda x: (x == "[]") or x is None)
]
print(
    f"There are still missing {len(still_missing)} coordinates. The rows are: {still_missing}"
)
print(cities_final.info())