Close

02/16/2019

Python package to get venues from Foursquare API into Pandas DataFrame

I’m working on my Capstone project for the IBM Data Science Professional Certificate Specialization on Coursera and wanted a fast and easy way to get venues around some coordinates. The way the explained in the course is fine, but I would like to have the data into a dataframe ready to use.

I found https://pypi.python.org/pypi/foursquare/() which works really good, but still had to clean the result, thus this.

I developed a small package called foursquare_api_tools that returns the venues in a dataframe with several columns. You can check the package in GitHub

https://github.com/dacog/foursquare_api_tools

You can use it in Jupyther Notebooks without problems. I tested it in IBM Cloud and https://labs.cognitiveclass.ai

Just install it using

[code language=”python”]!pip install foursquare

[/code]

Example of use

Import libraries

[code language=”python”]import foursquare as fs
from foursquare_api_tools import foursquare_api_tools as ft
[/code]

Initialize the client

[code language=”python”]CLIENT_ID = ‘YOUR_CLIENT_ID’ # your Foursquare ID
CLIENT_SECRET = ‘YOUR_SECRET’ # your Foursquare Secret
VERSION = ‘20180605’ # Foursquare API version
[/code]

this example uses Userless Auth

[code language=”python”]# Construct the client object using foursquare package
client = fs.Foursquare(client_id=CLIENT_ID, client_secret=CLIENT_SECRET, version=VERSION)
[/code]

Use the function

[code language=”python”]venues_explore(client,lat=’40.7233′,lng=’-74.0030′,limit=100, offset=2)
[/code]

Example

Here is an example notebook created on dataplatform.cloud.ibm.com
https://gist.github.com/e26e21df3b93860e75fc374be89a1a53()

Example output

Important

This is the first version and I’m using it for the project, but it can still have some bugs.

I’ll add more information and details in the future. In the meanwhile you are welcome to check the code on GitHub.

%d bloggers like this: