Learn
Gaining Insights
Flattening & Comparing

Now let’s use the two functions we added earlier to format our results.

First, we’ll use the flatten() function to flatten the JSON structure that the analyze() function returns, like so:

#First, flatten the results from the Watson PI API user = flatten(user_result) celebrity = flatten(celebrity_result)

Then, we’ll use the compare() function to compare the user and celebrity in order to gain insights on their personalities.

#Then, compare the results of the Watson PI API by calculating the distance between traits compared_results = compare(user,celebrity)

Instructions

1.

First, call the flatten() function on user_result. Store the result in a variable called user. Use the example above to help you.

2.

Next, call the flatten() function on celebrity_result. Store the result in a variable called celebrity. Use the example above to help you.

3.

Finally, call the compare() function and pass the user and celebrity variables as arguments. Store the result in a variable called compared_results. Use the example above to help you.

Folder Icon

Take this course for free

Already have an account?