

# www.globalsino.com/ICs/
# Find latitude and longitude with empty if the location is not found (None)

from geopy.geocoders import Nominatim
import pandas as pd

filename = r"C:\0Python\Michel\Combined 21-22 Wolf Kills - 21-22_calculated.csv"

# Read Pandas csv file with no header
df = pd.read_csv(filename, header=None)

for i in range(1, (len(df)- 1)):
    City_i = df.values[i][1]
    if df.loc[i, 2]:
        # Initialize Nominatim API
        geolocator = Nominatim(user_agent="MyApp")
        location = geolocator.geocode(City_i)
        if location != None:
            df.loc[i, 2] = location.latitude
            df.loc[i, 3] = location.longitude
            print(df.loc[i, 2])
        else:
            print("")
    df.to_csv(filename, header=False, index=False)
