Pandas has become the defacto package for data analysis. In this workshop, we are going to use the basics of pandas to analyze the interests of today's group. We are going to use meetup.com's api and fetch the list of interests that are listed in each of our meetup.com profile. We will compute which interests are common, which are uncommon, and find out how we can use topics of common interest to form teams for project night.
Lets get started by importing the essentials. You would need meetup.com's python api and pandas installed.
In [1]:
!pip install meetup-api
import meetup.api
import pandas as pd
from IPython.display import Image, display, HTML
from itertools import combinations
import sys
Next one of you need get a meetup.com API key. You will find it https://secure.meetup.com/meetup_api/key/ Also you'll need tonight's event id. Tonight's event id is the nine digit number in the meetup url.
In [73]:
API_KEY = '3f6d3275d3b6314e73453c4aa27'
event_id='239174132'
The following function uses the api and loads the data into a pandas data frame.
In [74]:
def get_members(event_id):
client = meetup.api.Client(API_KEY)
rsvps=client.GetRsvps(event_id=event_id, urlname='_ChiPy_')
member_id = ','.join([str(i['member']['member_id']) for i in rsvps.results])
return client.GetMembers(member_id=member_id)
def get_topics(members):
topics = set()
for member in members.results:
try:
for t in member['topics']:
topics.add(t['name'])
except:
print("Unexpected error:", sys.exc_info()[0])
raise
return list(topics)
def df_topics(event_id):
members = get_members(event_id=event_id)
topics = get_topics(members)
columns=['name','id','thumb_link'] + topics
data = []
for member in members.results:
topic_vector = [0]*len(topics)
for topic in member['topics']:
index = topics.index(topic['name'])
topic_vector[index] = 1
try:
data.append([member['name'], member['id'], member['photo']['thumb_link']] + topic_vector)
except KeyError:
data.append([member['name'], member['id'], 'NA'] + topic_vector)
except:
print("Unexpected error:", sys.exc_info()[0])
raise
return pd.DataFrame(data=data, columns=columns)
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
A, B - 6
A, C - 5
A, D - 4
B, C - 3
B, D - 2
C, D - 1
In [ ]: