How to Research LinkedIn Profiles in Tableau with Python and Azure Cognitive Services in Tableau

Azure Cognitive Services in Tableau: using Python to access the Web Services API provided by Microsoft Azure Cognitive Services
Azure Cognitive Services in Tableau: using Python to access the Web Services API provided by Microsoft Azure Cognitive Services

A few weeks after the fantastic Tableau Conference in New Orleans, I received an email from a data scientist who attended my TC18 social media session, and who is using Azure+Tableau. She had quite an interesting question:

How can a Tableau dashboard that displays contacts (name & company) automatically look up LinkedIn profile URLs?

Of course, researching LinkedIn profiles for a huge list of people is a very repetitive task. So let’s find a solution to improve this workflow…

Step by Step: Integrating Azure Cognitive Services in Tableau

1. Python and TabPy

We use Python to build API requests, communicate with Azure Cognitive Services and to verify the returned search results. In order to use Python within Tableau, we need to setup TabPy. If you haven’t done this yet: checkout my TabPy tutorial.

2. Microsoft Azure Cognitive Services

One of many APIs provided by Azure Cognitive Services is the Web Search API. We use this API to search for name + company + „linkedin“. The first three results are then validated by our Python script. One of the results should contain the corresponding LinkedIn profile.

3. Calculated Field in Tableau

Let’s wrap our Python script together and create a Calculated Field in Tableau:

SCRIPT_STR("
import http.client, urllib, base64, json
YOUR_API_KEY = 'xxx'
name = _arg1[0]
company = _arg2[0]
try:
headers = {'Ocp-Apim-Subscription-Key': YOUR_API_KEY }
params = urllib.urlencode({'q': name + ' ' + company + ' linkedin','count': '3'})
connection = http.client.HTTPSConnection('api.cognitive.microsoft.com')
connection.request('GET', '/bing/v7.0/search?%s' % params, '{body}', headers)
json_response = json.loads(connection.getresponse().read().decode('utf-8'))
connection.close()
for result in json_response['webPages']['value']:
if name.lower() in result['name'].lower():
if 'linkedin.com/in/' in result['displayUrl']:
return result['displayUrl']
break
except Exception as e:
return ''
return ''
", ATTR([Name]), ATTR([Company]))

4. Tableau dashboard with URL action

Adding a URL action with our new Calculated Field will do the trick. Now you can click on the LinkedIn icon and a new browser tab (or the LinkedIn app if installed) opens.

LinkedIn demo on Tableau Public

Is this useful for you? Feel free to download the Tableau workbook – don’t forget to add your API key!

Get More Insights

This tutorial is just the tip of the iceberg. If you want to dive deeper into the world of data visualization and analytics, don’t forget to order your copy of my new book, Visual Analytics with Tableau (Amazon).  This comprehensive guide offers an in-depth exploration of data visualization techniques and best practices.

I’d love to hear your thoughts. Feel free to leave a comment, share this tweet, and follow me on Twitter and LinkedIn for more tips, tricks, and tutorials on Azure Cognitive Services in Tableau and other data analytics topics.

Also, feel free to comment and share my Azure Cognitive Services in Tableau tweet: