Search code examples
jsonpython-3.xpandastableau-apigeocoding

Plot cities in tableau from longitude and latitude


I had JSON files which I cleaned and exported as csv files to be used in Tableau. The files have Longitude and Latitude fields, but I want to group them in Tableau by cities. How can I do so whether directly in Tableau or using Python?


Solution

  • Use geopy!!

    https://geopy.readthedocs.io/en/stable/#module-geopy.geocoders

    from geopy.geocoders import Nominatim
    
    geolocator = Nominatim(user_agent="specify_your_app_name_here")
    
    location = geolocator.reverse("52.509669, 13.376294")
    
    print(location.address)
    Potsdamer Platz, Mitte, Berlin, 10117, Deutschland, European Union
    
    print((location.latitude, location.longitude))
    (52.5094982, 13.3765983)
    
    print(location.raw)
    {'place_id': '654513', 'osm_type': 'node', ...}