Closed argythana closed 8 months ago
καλημέρα, μετα απο πολλά που δοκίμασα, βρήκατα τον συγκεκριμένο κώδικα για να υπολογίσει τις αποστάσεις μεταξύ των διευθύνσεων χρησιμοποιόντας την βιβλιοθήκη geopy: from geopy.geocoders import Nominatim from geopy.distance import geodesic
geolocator = Nominatim(user_agent="MyGeocodingApp_Marios_Melachroinos_v21.21")
def get_coordinates(address): location = geolocator.geocode(address) if location: return location.latitude, location.longitude else: return None
def calculate_distance(row): home_coords = get_coordinates(row['Home_adress']) work_coords = get_coordinates(row['Work_adress'])
if home_coords and work_coords:
return geodesic(home_coords, work_coords).kilometers
else:
return None
df['distance_km'] = df.apply(calculate_distance, axis=1)
Από τις 400 σειρές περίπου τις 130 δεν τις αναγνώρισε οπότε επέστρεψε τιμές NaN έχω 2 επιλογές. Η να κρατήσω τις αποστάσεις όπως τις βρήκα manually και να αναφέρω στην μεθοδολογία ότι ο παραπάνω κώδικας μπορει να αυτοματοποιήσει την διαδικασία όταν έχουμε παρα πολλα data. Ο άλλος τρόπος είναι να κρατήσω αποστάσεις από αυτά που μπόρεσε να υπολογίσει και σε αυτά που επέστρεψε NaN να τα αντικαταστήσω με αυτά που υπολόγισα μόνος. Ποιο πιστεύετε είναι καλύτερο
Ο άλλος τρόπος είναι να κρατήσω αποστάσεις από αυτά που μπόρεσε να υπολογίσει και σε αυτά που επέστρεψε NaN να τα αντικαταστήσω με αυτά που υπολόγισα μόνος.
This is the optimal way for your use-case (time constrain and project scope).
In a real life, big-data scenario, you should explore options to fill-in all addresses. For example:
You could manually check to see what the problem is with the missing addresses and correct the addresses.
Or find what are the reasons for not finding the geolocation.
Create a separate notebook. Use a file that includes only geolocation data for home and work (addresses. Postal Codes, City, etc.)
Try existing open source solutions. Detailed examples of algorithms you tried.