Skip to content

Instantly share code, notes, and snippets.

@MaximePawlakFr
Last active February 6, 2019 12:37
Show Gist options
  • Save MaximePawlakFr/01fcf54a94431f4b9fdd45035a52baa7 to your computer and use it in GitHub Desktop.
Save MaximePawlakFr/01fcf54a94431f4b9fdd45035a52baa7 to your computer and use it in GitHub Desktop.
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