Skip to content

Instantly share code, notes, and snippets.

@justinr922
Last active November 8, 2019 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinr922/99b88f0f932c184b94cdab2f780f3e23 to your computer and use it in GitHub Desktop.
Save justinr922/99b88f0f932c184b94cdab2f780f3e23 to your computer and use it in GitHub Desktop.
Converts Location Column to "Latitude" and "Longitude" columns
# Each coordinate is in the form of a dictionary like so:
#
# {'latitude': 34.3, 'longitude': -89.5}
#
# So we will use list compreshension to create a new column,
# using dictionary.get(key) to access each value.
location_df['latitude'] = [value.get('latitude') for value in location_df['coordinate']]
location_df['longitude'] = [value.get('longitude') for value in location_df['coordinate']]
#And drop the old coordinate column, since we have gotten what we need out of it
location_df.drop('coordinate', axis=1, inplace=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment