Last active
July 27, 2020 06:33
-
-
Save NP-chaonay/11b3b2f737a3a253a2599e88963f3fea to your computer and use it in GitHub Desktop.
Mentimeter Wordcloud Question Scraping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Mentimeter Wordcloud Question Scraping | |
import http.client,json | |
import pandas as pd | |
question_id='000000000000' | |
HTTP_C=http.client.HTTPSConnection('api.mentimeter.com') | |
HTTP_C.request('GET','/questions/'+question_id+'/result?isPublic=true') | |
HTTP_R=HTTP_C.getresponse() | |
data=HTTP_R.read() | |
data=json.loads(data) | |
data=data['results'] | |
words_bin=[] | |
for word in words: words_bin+=[word] | |
for respondent in data: | |
words=respondent.split() | |
df=pd.DataFrame(words_bin)[0].value_counts().agg([lambda x: 100*x/len(words_bin),lambda x: x]) | |
df.columns=['%','count'] | |
df.nlargest(10,'count','all') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment