Last active
June 3, 2020 01:10
-
-
Save mostafam/08f310251a990cb9d8bf690317847c5b to your computer and use it in GitHub Desktop.
Take2 modified
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
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