This commit is contained in:
2026-02-15 10:24:59 -08:00
commit 44436ffe6f
3 changed files with 13135 additions and 0 deletions

13104
africapolis.csv Normal file

File diff suppressed because it is too large Load Diff

23
citydist.py Normal file
View File

@@ -0,0 +1,23 @@
import pandas as pd
import numpy as np
from geopy.distance import geodesic
def closest_city(point, df=None, population_threshold=0):
"""Get the name, population, and distance to the point of the closest city"""
if df is None:
df = pd.read_csv("africapolis.csv", index_col=0)
df = df[df["Population"] > population_threshold]
distances = df.apply(lambda row: geodesic(point, (row["Latitude"], row["Longitude"])), axis=1)
min_index = distances.idxmin()
city = df.loc[min_index]
return {
"name": city["Name"],
"population": np.int64(city["Population"]),
"distance": np.float64(distances[min_index].km),
"location": (city["Latitude"], city["Longitude"])
}
df = pd.read_csv("africapolis.csv", index_col=0)
print(closest_city((0,0), df=df, population_threshold=50000))

8
requirements.txt Normal file
View File

@@ -0,0 +1,8 @@
et_xmlfile==2.0.0
geographiclib==2.1
geopy==2.4.1
numpy==2.4.2
openpyxl==3.1.5
pandas==3.0.0
python-dateutil==2.9.0.post0
six==1.17.0