Skip to content

Instantly share code, notes, and snippets.

@mostafam
Last active June 3, 2020 01:10
Show Gist options
  • Save mostafam/08f310251a990cb9d8bf690317847c5b to your computer and use it in GitHub Desktop.
Save mostafam/08f310251a990cb9d8bf690317847c5b to your computer and use it in GitHub Desktop.
Take2 modified
from pyspark.sql.functions import udf, col
@udf('string')
def get_zip_udf3(latitude, longitude):
search = SearchEngine(db_file_dir="/tmp/db")
try:
zip = search.by_coordinates(latitude, longitude, returns=1)[0].to_dict()["zipcode"]
except:
zip = 'bad'
return zip
df.withColumn('zip', get_zip_udf3(col("latitude"),col("longitude"))).show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment