fix([2fd88f42]): handle malformed header in PLZ csv dataset
This commit is contained in:
@@ -26,13 +26,19 @@ def load_plz_data():
|
|||||||
global plz_geocoord_df
|
global plz_geocoord_df
|
||||||
try:
|
try:
|
||||||
print("--- Loading PLZ geocoordinates dataset... ---")
|
print("--- Loading PLZ geocoordinates dataset... ---")
|
||||||
df = pd.read_csv("plz_geocoord.csv", dtype={'plz': str})
|
# The CSV has a malformed header. We read it and assign names manually.
|
||||||
|
df = pd.read_csv("plz_geocoord.csv", dtype=str)
|
||||||
|
# Rename the columns based on their expected order: PLZ, Latitude, Longitude
|
||||||
|
df.columns = ['plz', 'y', 'x']
|
||||||
|
|
||||||
df['plz'] = df['plz'].str.zfill(5)
|
df['plz'] = df['plz'].str.zfill(5)
|
||||||
plz_geocoord_df = df.set_index('plz')
|
plz_geocoord_df = df.set_index('plz')
|
||||||
print(f"--- Successfully loaded {len(plz_geocoord_df)} PLZ coordinates. ---")
|
print(f"--- Successfully loaded {len(plz_geocoord_df)} PLZ coordinates. ---")
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print("--- FATAL ERROR: plz_geocoord.csv not found. Geocoding will not work. ---")
|
print("--- FATAL ERROR: plz_geocoord.csv not found. Geocoding will not work. ---")
|
||||||
# In a real app, you might want to exit or handle this more gracefully
|
plz_geocoord_df = pd.DataFrame()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"--- FATAL ERROR loading plz_geocoord.csv: {e} ---")
|
||||||
plz_geocoord_df = pd.DataFrame()
|
plz_geocoord_df = pd.DataFrame()
|
||||||
|
|
||||||
# --- Pydantic Models ---
|
# --- Pydantic Models ---
|
||||||
|
|||||||
Reference in New Issue
Block a user