0

So I have a dataframe with 2 rows, it looks like this:

    latitude  longitude
0  39.696103 -84.138461
1  39.696103 -84.138461
2  39.696103 -84.138461
3  39.696103 -84.138461
4  39.696103 -84.138461

note that the latitude and longitude are not always the same, but clearly at this time, the person was in the same place

Now there are many search engines online in which I can give a latitude and longitude and it will tell me the location. So my question is:

What modules can I use and what about them do I use that will be able to run these values through the search engine, take the outputted location, and put it in a list so that I can use the following code to make a 3rd column:

df['location'] = location_list

After everything works out the following dataframe should look as such:

    latitude  longitude               location
0  39.696103 -84.138461  Dayton, OH 45429, USA
1  39.696103 -84.138461  Dayton, OH 45429, USA
2  39.696103 -84.138461  Dayton, OH 45429, USA
3  39.696103 -84.138461  Dayton, OH 45429, USA
4  39.696103 -84.138461  Dayton, OH 45429, USA

If it's helpful, I use this website for the conversion

Ryan Saxe
  • 17,123
  • 23
  • 80
  • 128

1 Answers1

3

If you're asking specifically about using the website you mentioned, LatLong.net, then the answer is that there is no Python library to do what you're asking (unless you want to try to integrate Python and JavaScript).

If you take a look at the source code of the latLong.net page, you'll see that it is entirely JavaScript based. The line geocoder = new google.maps.Geocoder(); indicates that they are using the Google Geocoding API.

If you want to use the Google Geocoding API, I'd suggest you search for related answers to that. Here are some that appear relevant:

If you want an offline solution then you need to look into perhaps downloading shapefiles (see Reverse Geocoding Without Web Access) and using something like Shapely, or perhaps using k-nearest neighbors on a set of points. For KNN you could use cities (see geonames) or countries (see my country.py file).

Community
  • 1
  • 1
Wesley Baugh
  • 3,720
  • 4
  • 24
  • 42
  • this seems promising, but can it be done not on a server and just on my local computer? It wasn't clear if that was possible through looking at the links... – Ryan Saxe May 10 '13 at 00:36
  • @RyanSaxe if you use any sort of API then no, you'll need to be connected online in order to use them. I've updated my answer with more details. – Wesley Baugh May 10 '13 at 00:43