Last active
February 6, 2019 12:37
-
-
Save MaximePawlakFr/01fcf54a94431f4b9fdd45035a52baa7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import geocoder | |
import os | |
mapbox_token = os.environ['MAPBOX_TOKEN'] | |
assert mapbox_token | |
from pandas import Series | |
def georeverse(point): | |
return geocoder.mapbox(point, method='reverse',key=mapbox_token) | |
def get_city_and_postal(point): | |
g = georeverse(point) | |
return (g.city, g.postal) | |
def add_geo_point(df): | |
res = df.copy() | |
for index, row in df.iterrows(): | |
if(index%10==0): | |
print(index,"/", df.shape[0]) | |
point = row["point"] | |
data = get_city_and_postal(point) | |
res.loc[index, "ville"] = data[0] | |
res.loc[index, "postal"] = data[1] | |
return res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment