I want to geocode a number of universities in Europe (stored in a csv file). The csv file contains only one column (Name). However, I am yet to complete the work, since my code contains bugs. When I ran the code, I got ValueError: Columns must be same length as key
. This occurred on the last line. How do I solve this?
Here's a sample of the code I used:
from geopy.geocoders import Nominatim
import pandas as pd
import numpy as np
geolocator = Nominatim(user_agent = 'ed')
universities = pd.read_csv("Z:/data/top_universities.csv")
def my_geocoder(row):
try:
point = geolocator.geocode(row).point
return pd.Series({'Latitude': point.latitude, 'Longitude': point.longitude})
except:
return None
universities[['Latitude', 'Longitude']] = universities.apply(lambda x: my_geocoder(x['Name']), axis=1)