{ "cells": [ { "cell_type": "markdown", "id": "66b45bb9", "metadata": {}, "source": [ "# Final Project" ] }, { "cell_type": "markdown", "id": "6e07d13e", "metadata": {}, "source": [ "I love watching TV series and movies, most recently Ted Lasso seems to be the talk of the town. I loved the first season and can't wait to watch the second season. I also have an interest in the Emmy's, I watch it every year. The reason for this analysis is to determine if Twitter has any influence on the Emmy winner of Best Comedy Series. I first pulled Tweets that mention Ted Lasso or #tedlasso along with blackish or #blackish. Once I got a reasonable amount of Tweets i used the VADER toolkit(?) to determine the positive and negative sentiments of the Tweets that i pulled. Using VADER i can measure the sentiment of the Tweets to then compare the two shows. Once i got the sentiments of each show i created a histogram of the negative, positive, neutral, and compound of the tweets. This allowed me to get a visual of each sentiment and see which had more weight to it. Looking at these graphs comparatively, I can estimate that Ted Lasso has more positive Tweets than blackish. " ] }, { "cell_type": "code", "execution_count": 2, "id": "195ca0a5", "metadata": {}, "outputs": [], "source": [ "import requests\n", "import pandas as pd\n", "import urllib\n", "import json" ] }, { "cell_type": "code", "execution_count": 3, "id": "2b330167", "metadata": {}, "outputs": [], "source": [ "bearer_token = pd.read_csv('bearer_token.txt', header = 0)" ] }, { "cell_type": "code", "execution_count": null, "id": "ec5074d7", "metadata": {}, "outputs": [], "source": [ "bearer_token" ] }, { "cell_type": "code", "execution_count": null, "id": "3d0ca646", "metadata": {}, "outputs": [], "source": [ "bearer_token['bearer_token'].iloc[0]" ] }, { "cell_type": "code", "execution_count": 6, "id": "cf977181", "metadata": {}, "outputs": [], "source": [ "header = {'Authorization' : 'Bearer {}'.format(bearer_token['bearer_token'].iloc[0])}" ] }, { "cell_type": "code", "execution_count": 7, "id": "9902fd9a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['bearer_token'], dtype='object')" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bearer_token.keys()" ] }, { "cell_type": "code", "execution_count": 8, "id": "716041a7", "metadata": {}, "outputs": [], "source": [ "endpoint_url = 'https://api.twitter.com/2/tweets/search/recent'" ] }, { "cell_type": "code", "execution_count": 9, "id": "f8e99bb4", "metadata": {}, "outputs": [], "source": [ "query = urllib.parse.quote('(#TedLasso OR Ted Lasso lang:en)')" ] }, { "cell_type": "code", "execution_count": 10, "id": "ee6288bf", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'%28%23TedLasso%20OR%20Ted%20Lasso%20lang%3Aen%29'" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "query" ] }, { "cell_type": "code", "execution_count": 11, "id": "cf53e4d4", "metadata": {}, "outputs": [], "source": [ "my_api_url = endpoint_url + '?query={}'.format(query)" ] }, { "cell_type": "code", "execution_count": 12, "id": "3324a2c4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'https://api.twitter.com/2/tweets/search/recent?query=%28%23TedLasso%20OR%20Ted%20Lasso%20lang%3Aen%29'" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "my_api_url" ] }, { "cell_type": "code", "execution_count": 13, "id": "7b6fa438", "metadata": {}, "outputs": [], "source": [ "tweet_fields = 'public_metrics,created_at,author_id,lang'" ] }, { "cell_type": "code", "execution_count": 14, "id": "8cd30266", "metadata": {}, "outputs": [], "source": [ "my_api_url = endpoint_url + '?query={}&tweet.fields={}'.format(query, tweet_fields)" ] }, { "cell_type": "code", "execution_count": 15, "id": "50081342", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'https://api.twitter.com/2/tweets/search/recent?query=%28%23TedLasso%20OR%20Ted%20Lasso%20lang%3Aen%29&tweet.fields=public_metrics,created_at,author_id,lang'" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "my_api_url" ] }, { "cell_type": "code", "execution_count": 16, "id": "03ffca74", "metadata": {}, "outputs": [], "source": [ "expansions = 'author_id'" ] }, { "cell_type": "code", "execution_count": 17, "id": "8e639e27", "metadata": {}, "outputs": [], "source": [ "url = endpoint_url + '?query={}&max_results=10&tweet.fields{}'.format(query, tweet_fields)" ] }, { "cell_type": "code", "execution_count": 18, "id": "99ed4b2a", "metadata": {}, "outputs": [], "source": [ "response = requests.request(\"GET\", url, headers = header)" ] }, { "cell_type": "code", "execution_count": 19, "id": "968f6c08", "metadata": {}, "outputs": [], "source": [ "url_expansions = endpoint_url + '?query={}&max_results=100&tweet.fields={}&expansions={}&user.fields={}'.format(query, tweet_fields, expansions, 'username')" ] }, { "cell_type": "code", "execution_count": 20, "id": "3639f51e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'https://api.twitter.com/2/tweets/search/recent?query=%28%23TedLasso%20OR%20Ted%20Lasso%20lang%3Aen%29&max_results=100&tweet.fields=public_metrics,created_at,author_id,lang&expansions=author_id&user.fields=username'" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "url_expansions" ] }, { "cell_type": "code", "execution_count": 21, "id": "409787d5", "metadata": {}, "outputs": [], "source": [ "first_response = requests.request(\"GET\", url_expansions, headers = header)" ] }, { "cell_type": "code", "execution_count": null, "id": "76e895f8", "metadata": {}, "outputs": [], "source": [ "first_response.text" ] }, { "cell_type": "code", "execution_count": 23, "id": "6818c993", "metadata": {}, "outputs": [], "source": [ "first_dict = json.loads(first_response.text)" ] }, { "cell_type": "code", "execution_count": 24, "id": "69052a8c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "dict_keys(['data', 'includes', 'meta'])" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "first_dict.keys()" ] }, { "cell_type": "code", "execution_count": 25, "id": "aafd8903", "metadata": {}, "outputs": [], "source": [ "my_df = pd.DataFrame(first_dict['data'])" ] }, { "cell_type": "code", "execution_count": 26, "id": "3b0c179e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | author_id | \n", "text | \n", "created_at | \n", "id | \n", "public_metrics | \n", "lang | \n", "
---|---|---|---|---|---|---|
0 | \n", "1855042940 | \n", "RT @goldenglobes: The #GoldenGlobes nominees f... | \n", "2021-12-13T23:40:21.000Z | \n", "1470539115343011846 | \n", "{'retweet_count': 48, 'reply_count': 0, 'like_... | \n", "en | \n", "
1 | \n", "1322320427507765248 | \n", "RT @JarettSays: My heart feels so full when I ... | \n", "2021-12-13T23:40:06.000Z | \n", "1470539054353629189 | \n", "{'retweet_count': 43, 'reply_count': 0, 'like_... | \n", "en | \n", "
2 | \n", "152531825 | \n", "RT @QUEERLASSO: I dont think we talk about thi... | \n", "2021-12-13T23:39:52.000Z | \n", "1470538993666301952 | \n", "{'retweet_count': 154, 'reply_count': 0, 'like... | \n", "en | \n", "
3 | \n", "25866804 | \n", "late to ted lasso but woowee that nate charact... | \n", "2021-12-13T23:39:37.000Z | \n", "1470538932492324864 | \n", "{'retweet_count': 0, 'reply_count': 0, 'like_c... | \n", "en | \n", "
4 | \n", "1060508317204791296 | \n", "RT @QUEERLASSO: I dont think we talk about thi... | \n", "2021-12-13T23:39:06.000Z | \n", "1470538802523430912 | \n", "{'retweet_count': 154, 'reply_count': 0, 'like... | \n", "en | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
95 | \n", "294151373 | \n", "RT @goldenglobes: The #GoldenGlobes nominees f... | \n", "2021-12-13T23:12:34.000Z | \n", "1470532126265204736 | \n", "{'retweet_count': 48, 'reply_count': 0, 'like_... | \n", "en | \n", "
96 | \n", "1909483010 | \n", "RT @WestLondonFS: The @goldenglobes nomination... | \n", "2021-12-13T23:11:56.000Z | \n", "1470531964050370561 | \n", "{'retweet_count': 34, 'reply_count': 0, 'like_... | \n", "en | \n", "
97 | \n", "1392853644840685570 | \n", "📸 | jason sudeikis, the cast of ted lasso and ... | \n", "2021-12-13T23:11:13.000Z | \n", "1470531785352228867 | \n", "{'retweet_count': 9, 'reply_count': 0, 'like_c... | \n", "en | \n", "
98 | \n", "828768590392389632 | \n", "RT @DiscussingFilm: The #GoldenGlobes nominees... | \n", "2021-12-13T23:11:05.000Z | \n", "1470531751131086848 | \n", "{'retweet_count': 216, 'reply_count': 0, 'like... | \n", "en | \n", "
99 | \n", "1076748693490016256 | \n", "RT @DiscussingFilm: The #GoldenGlobes nominees... | \n", "2021-12-13T23:10:09.000Z | \n", "1470531518502158336 | \n", "{'retweet_count': 332, 'reply_count': 0, 'like... | \n", "en | \n", "
100 rows × 6 columns
\n", "\n", " | author_id | \n", "text | \n", "created_at | \n", "id | \n", "public_metrics | \n", "lang | \n", "
---|---|---|---|---|---|---|
0 | \n", "1855042940 | \n", "RT @goldenglobes: The #GoldenGlobes nominees f... | \n", "2021-12-13T23:40:21.000Z | \n", "1470539115343011846 | \n", "{'retweet_count': 48, 'reply_count': 0, 'like_... | \n", "en | \n", "
1 | \n", "1322320427507765248 | \n", "RT @JarettSays: My heart feels so full when I ... | \n", "2021-12-13T23:40:06.000Z | \n", "1470539054353629189 | \n", "{'retweet_count': 43, 'reply_count': 0, 'like_... | \n", "en | \n", "
2 | \n", "152531825 | \n", "RT @QUEERLASSO: I dont think we talk about thi... | \n", "2021-12-13T23:39:52.000Z | \n", "1470538993666301952 | \n", "{'retweet_count': 154, 'reply_count': 0, 'like... | \n", "en | \n", "
3 | \n", "25866804 | \n", "late to ted lasso but woowee that nate charact... | \n", "2021-12-13T23:39:37.000Z | \n", "1470538932492324864 | \n", "{'retweet_count': 0, 'reply_count': 0, 'like_c... | \n", "en | \n", "
4 | \n", "1060508317204791296 | \n", "RT @QUEERLASSO: I dont think we talk about thi... | \n", "2021-12-13T23:39:06.000Z | \n", "1470538802523430912 | \n", "{'retweet_count': 154, 'reply_count': 0, 'like... | \n", "en | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
195 | \n", "1575603678 | \n", "RT @BatatinhaGeek: As indicadas a 'Melhor Atri... | \n", "2021-12-13T22:35:03.000Z | \n", "1470522682773061635 | \n", "{'retweet_count': 1, 'reply_count': 0, 'like_c... | \n", "en | \n", "
196 | \n", "1575603678 | \n", "RT @BatatinhaGeek: Os indicados a 'Melhor Ator... | \n", "2021-12-13T22:35:01.000Z | \n", "1470522675860754434 | \n", "{'retweet_count': 2, 'reply_count': 0, 'like_c... | \n", "en | \n", "
197 | \n", "363940693 | \n", "In honor of the holiday season and the upcomin... | \n", "2021-12-13T22:34:33.000Z | \n", "1470522556549668869 | \n", "{'retweet_count': 0, 'reply_count': 1, 'like_c... | \n", "en | \n", "
198 | \n", "471528838 | \n", "I miss Ted Lasso Twitter https://t.co/N5dQWP14hd | \n", "2021-12-13T22:34:04.000Z | \n", "1470522434923089924 | \n", "{'retweet_count': 0, 'reply_count': 0, 'like_c... | \n", "en | \n", "
199 | \n", "1409283084520890370 | \n", "RT @manvillebea: if there’s one thing the ted ... | \n", "2021-12-13T22:33:52.000Z | \n", "1470522384541052928 | \n", "{'retweet_count': 3, 'reply_count': 0, 'like_c... | \n", "en | \n", "
200 rows × 6 columns
\n", "\n", " | neg | \n", "neu | \n", "pos | \n", "compound | \n", "
---|---|---|---|---|
0 | \n", "0.000 | \n", "0.729 | \n", "0.271 | \n", "0.7717 | \n", "
1 | \n", "0.000 | \n", "0.769 | \n", "0.231 | \n", "0.6369 | \n", "
2 | \n", "0.000 | \n", "1.000 | \n", "0.000 | \n", "0.0000 | \n", "
3 | \n", "0.000 | \n", "1.000 | \n", "0.000 | \n", "0.0000 | \n", "
4 | \n", "0.000 | \n", "1.000 | \n", "0.000 | \n", "0.0000 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
188 | \n", "0.091 | \n", "0.785 | \n", "0.124 | \n", "0.2023 | \n", "
189 | \n", "0.087 | \n", "0.794 | \n", "0.119 | \n", "0.2023 | \n", "
190 | \n", "0.000 | \n", "0.730 | \n", "0.270 | \n", "0.9551 | \n", "
191 | \n", "0.242 | \n", "0.758 | \n", "0.000 | \n", "-0.1531 | \n", "
192 | \n", "0.095 | \n", "0.905 | \n", "0.000 | \n", "-0.3182 | \n", "
193 rows × 4 columns
\n", "\n", " | id | \n", "public_metrics | \n", "text | \n", "created_at | \n", "author_id | \n", "lang | \n", "
---|---|---|---|---|---|---|
0 | \n", "1470539115921870855 | \n", "{'retweet_count': 0, 'reply_count': 0, 'like_c... | \n", "blackish-grey ossel hitch | \n", "2021-12-13T23:40:21.000Z | \n", "796444880675438592 | \n", "en | \n", "
1 | \n", "1470539014117765122 | \n", "{'retweet_count': 2, 'reply_count': 0, 'like_c... | \n", "RT @IamW4TC: Congratulations @IssaRae and @Tra... | \n", "2021-12-13T23:39:56.000Z | \n", "957821109444972545 | \n", "en | \n", "
2 | \n", "1470527694148452358 | \n", "{'retweet_count': 0, 'reply_count': 0, 'like_c... | \n", "And I really feel like they nominate Blackish ... | \n", "2021-12-13T22:54:58.000Z | \n", "26905493 | \n", "en | \n", "
3 | \n", "1470527263489802240 | \n", "{'retweet_count': 0, 'reply_count': 1, 'like_c... | \n", "@Chemicalboyy Banshee\\nVikings\\nElites\\nBlacki... | \n", "2021-12-13T22:53:15.000Z | \n", "1080035996027273217 | \n", "en | \n", "
4 | \n", "1470520951964065796 | \n", "{'retweet_count': 0, 'reply_count': 0, 'like_c... | \n", "3) Mejor actor principal en comedia #GlobosDeO... | \n", "2021-12-13T22:28:10.000Z | \n", "1863836348 | \n", "es | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
95 | \n", "1470204422399610884 | \n", "{'retweet_count': 0, 'reply_count': 0, 'like_c... | \n", "Blackish be so inspiring like I wanna be succe... | \n", "2021-12-13T01:30:24.000Z | \n", "2398245080 | \n", "en | \n", "
96 | \n", "1470203673200537601 | \n", "{'retweet_count': 2, 'reply_count': 0, 'like_c... | \n", "RT @johnrfisher1: Been kinda snowbound of late... | \n", "2021-12-13T01:27:25.000Z | \n", "1463583253714059269 | \n", "en | \n", "
97 | \n", "1470202539828289537 | \n", "{'retweet_count': 3, 'reply_count': 0, 'like_c... | \n", "RT @ChastyRaunchSub: A third item from the AC ... | \n", "2021-12-13T01:22:55.000Z | \n", "1328506635397046273 | \n", "en | \n", "
98 | \n", "1470193554962145282 | \n", "{'retweet_count': 0, 'reply_count': 0, 'like_c... | \n", "The tv show Blackish is racist, unless there i... | \n", "2021-12-13T00:47:13.000Z | \n", "1319384189968461826 | \n", "en | \n", "
99 | \n", "1470192856186990595 | \n", "{'retweet_count': 0, 'reply_count': 0, 'like_c... | \n", "Blackish is ending? A show I swore I'd never w... | \n", "2021-12-13T00:44:26.000Z | \n", "242948954 | \n", "en | \n", "
100 rows × 6 columns
\n", "\n", " | id | \n", "public_metrics | \n", "text | \n", "created_at | \n", "author_id | \n", "lang | \n", "
---|---|---|---|---|---|---|
0 | \n", "1470539115921870855 | \n", "{'retweet_count': 0, 'reply_count': 0, 'like_c... | \n", "blackish-grey ossel hitch | \n", "2021-12-13T23:40:21.000Z | \n", "796444880675438592 | \n", "en | \n", "
1 | \n", "1470539014117765122 | \n", "{'retweet_count': 2, 'reply_count': 0, 'like_c... | \n", "RT @IamW4TC: Congratulations @IssaRae and @Tra... | \n", "2021-12-13T23:39:56.000Z | \n", "957821109444972545 | \n", "en | \n", "
2 | \n", "1470527694148452358 | \n", "{'retweet_count': 0, 'reply_count': 0, 'like_c... | \n", "And I really feel like they nominate Blackish ... | \n", "2021-12-13T22:54:58.000Z | \n", "26905493 | \n", "en | \n", "
3 | \n", "1470527263489802240 | \n", "{'retweet_count': 0, 'reply_count': 1, 'like_c... | \n", "@Chemicalboyy Banshee\\nVikings\\nElites\\nBlacki... | \n", "2021-12-13T22:53:15.000Z | \n", "1080035996027273217 | \n", "en | \n", "
4 | \n", "1470520951964065796 | \n", "{'retweet_count': 0, 'reply_count': 0, 'like_c... | \n", "3) Mejor actor principal en comedia #GlobosDeO... | \n", "2021-12-13T22:28:10.000Z | \n", "1863836348 | \n", "es | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
195 | \n", "1469655354086760451 | \n", "{'retweet_count': 1, 'reply_count': 0, 'like_c... | \n", "That girl from Blackish... https://t.co/JNoPuq... | \n", "2021-12-11T13:08:35.000Z | \n", "984971006245769216 | \n", "en | \n", "
196 | \n", "1469651840207884288 | \n", "{'retweet_count': 15, 'reply_count': 0, 'like_... | \n", "RT @_myvpl_: @NCares17 @jessicawhitIly Yh it w... | \n", "2021-12-11T12:54:38.000Z | \n", "387132443 | \n", "en | \n", "
197 | \n", "1469648138906763267 | \n", "{'retweet_count': 15, 'reply_count': 0, 'like_... | \n", "RT @_myvpl_: @NCares17 @jessicawhitIly Yh it w... | \n", "2021-12-11T12:39:55.000Z | \n", "452280828 | \n", "en | \n", "
198 | \n", "1469624514417991681 | \n", "{'retweet_count': 195, 'reply_count': 0, 'like... | \n", "RT @VasuBharat09: It's a ray.\\nLight and warmt... | \n", "2021-12-11T11:06:03.000Z | \n", "813312379509506049 | \n", "en | \n", "
199 | \n", "1469622812642091010 | \n", "{'retweet_count': 6, 'reply_count': 0, 'like_c... | \n", "RT @TvBoxSA: اعلنت @ABCNetwork تجديد المسلسل ا... | \n", "2021-12-11T10:59:17.000Z | \n", "1067634457 | \n", "ar | \n", "
200 rows × 6 columns
\n", "\n", " | neg | \n", "neu | \n", "pos | \n", "compound | \n", "
---|---|---|---|---|
0 | \n", "0.000 | \n", "1.000 | \n", "0.000 | \n", "0.0000 | \n", "
1 | \n", "0.000 | \n", "0.690 | \n", "0.310 | \n", "0.8442 | \n", "
2 | \n", "0.207 | \n", "0.692 | \n", "0.101 | \n", "-0.4441 | \n", "
3 | \n", "0.000 | \n", "1.000 | \n", "0.000 | \n", "0.0000 | \n", "
4 | \n", "0.102 | \n", "0.800 | \n", "0.098 | \n", "-0.0258 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
188 | \n", "0.000 | \n", "1.000 | \n", "0.000 | \n", "0.0000 | \n", "
189 | \n", "0.000 | \n", "1.000 | \n", "0.000 | \n", "0.0000 | \n", "
190 | \n", "0.000 | \n", "0.798 | \n", "0.202 | \n", "0.6486 | \n", "
191 | \n", "0.000 | \n", "0.798 | \n", "0.202 | \n", "0.6486 | \n", "
192 | \n", "0.087 | \n", "0.758 | \n", "0.155 | \n", "0.3182 | \n", "
193 rows × 4 columns
\n", "