July 2017
Beginner to intermediate
312 pages
7h 27m
English
In order to use the Alchemy API we will first create a function that makes the requests to the service:
import requests
import json
apikey = "YOUR_KEY"
url = "https://gateway-a.watsonplatform.net/calls/text/TextGetEmotion"
def get_alchemy(apikey,text):
pms = {'apikey' : apikey, 'outputMode' : 'json', "text" : text}
result = requests.post(url, data = pms)
try:
emotions = json.loads(result.text)['docEmotions']
except:
emotions = None
return(emotions)
The free version of the alchemy API is limited to 1000 requests per month. For our analysis, we will take the first 1000 comments:
alchemy = df_comments.head(1000)
Then, we apply the alchemy API on each message in our dataset using the apply method. We store the results ...
Read now
Unlock full access