1. Local and global thought patterns

While we might not be Twitter fans, we have to admit that it has a huge influence on the world (who doesn't know about Trump's tweets). Twitter data is not only gold in terms of insights, but Twitter-storms are available for analysis in near real-time. This means we can learn about the big waves of thoughts and moods around the world as they arise.

As any place filled with riches, Twitter has security guards blocking us from laying our hands on the data right away ⛔️ Some authentication steps (really straightforward) are needed to call their APIs for data collection. Since our goal today is learning to extract insights from data, we have already gotten a green-pass from security ✅ Our data is ready for usage in the datasets folder — we can concentrate on the fun part! 🕵️‍♀️🌎



Twitter provides both global and local trends. Let's load and inspect data for topics that were hot worldwide (WW) and in the United States (US) at the moment of query — snapshot of JSON response from the call to Twitter's GET trends/place API.

Note: Here is the documentation for this call, and here a full overview on Twitter's APIs.

In [1]:
# Loading json module
import json 

# Loading WW_trends and US_trends data
WW_trends = json.loads(open('datasets/WWTrends.json').read())
US_trends = json.loads(open('datasets/USTrends.json').read())

# Inspecting data by printing out WW_trends and US_trends variables
print(WW_trends)
print(US_trends)
[{'trends': [{'name': '#BeratKandili', 'url': 'http://twitter.com/search?q=%23BeratKandili', 'promoted_content': None, 'query': '%23BeratKandili', 'tweet_volume': 46373}, {'name': '#GoodFriday', 'url': 'http://twitter.com/search?q=%23GoodFriday', 'promoted_content': None, 'query': '%23GoodFriday', 'tweet_volume': 81891}, {'name': '#WeLoveTheEarth', 'url': 'http://twitter.com/search?q=%23WeLoveTheEarth', 'promoted_content': None, 'query': '%23WeLoveTheEarth', 'tweet_volume': 159698}, {'name': '#195TLdenTTVerilir', 'url': 'http://twitter.com/search?q=%23195TLdenTTVerilir', 'promoted_content': None, 'query': '%23195TLdenTTVerilir', 'tweet_volume': None}, {'name': '#AFLNorthDons', 'url': 'http://twitter.com/search?q=%23AFLNorthDons', 'promoted_content': None, 'query': '%23AFLNorthDons', 'tweet_volume': None}, {'name': 'Shiv Sena', 'url': 'http://twitter.com/search?q=%22Shiv+Sena%22', 'promoted_content': None, 'query': '%22Shiv+Sena%22', 'tweet_volume': None}, {'name': 'Lyra McKee', 'url': 'http://twitter.com/search?q=%22Lyra+McKee%22', 'promoted_content': None, 'query': '%22Lyra+McKee%22', 'tweet_volume': 17606}, {'name': 'Priyanka Chaturvedi', 'url': 'http://twitter.com/search?q=%22Priyanka+Chaturvedi%22', 'promoted_content': None, 'query': '%22Priyanka+Chaturvedi%22', 'tweet_volume': 22342}, {'name': 'Derry', 'url': 'http://twitter.com/search?q=Derry', 'promoted_content': None, 'query': 'Derry', 'tweet_volume': 28234}, {'name': '池袋の事故', 'url': 'http://twitter.com/search?q=%E6%B1%A0%E8%A2%8B%E3%81%AE%E4%BA%8B%E6%95%85', 'promoted_content': None, 'query': '%E6%B1%A0%E8%A2%8B%E3%81%AE%E4%BA%8B%E6%95%85', 'tweet_volume': 34381}, {'name': 'プリウス', 'url': 'http://twitter.com/search?q=%E3%83%97%E3%83%AA%E3%82%A6%E3%82%B9', 'promoted_content': None, 'query': '%E3%83%97%E3%83%AA%E3%82%A6%E3%82%B9', 'tweet_volume': 22944}, {'name': 'Hemant Karkare', 'url': 'http://twitter.com/search?q=%22Hemant+Karkare%22', 'promoted_content': None, 'query': '%22Hemant+Karkare%22', 'tweet_volume': 24067}, {'name': '高齢者', 'url': 'http://twitter.com/search?q=%E9%AB%98%E9%BD%A2%E8%80%85', 'promoted_content': None, 'query': '%E9%AB%98%E9%BD%A2%E8%80%85', 'tweet_volume': 28382}, {'name': '브이알', 'url': 'http://twitter.com/search?q=%EB%B8%8C%EC%9D%B4%EC%95%8C', 'promoted_content': None, 'query': '%EB%B8%8C%EC%9D%B4%EC%95%8C', 'tweet_volume': 15490}, {'name': '刀ステ', 'url': 'http://twitter.com/search?q=%E5%88%80%E3%82%B9%E3%83%86', 'promoted_content': None, 'query': '%E5%88%80%E3%82%B9%E3%83%86', 'tweet_volume': None}, {'name': '免許返納', 'url': 'http://twitter.com/search?q=%E5%85%8D%E8%A8%B1%E8%BF%94%E7%B4%8D', 'promoted_content': None, 'query': '%E5%85%8D%E8%A8%B1%E8%BF%94%E7%B4%8D', 'tweet_volume': None}, {'name': 'Berat Kandilimiz', 'url': 'http://twitter.com/search?q=%22Berat+Kandilimiz%22', 'promoted_content': None, 'query': '%22Berat+Kandilimiz%22', 'tweet_volume': 10901}, {'name': 'örgütdeğil arkadaşgrubu', 'url': 'http://twitter.com/search?q=%22%C3%B6rg%C3%BCtde%C4%9Fil+arkada%C5%9Fgrubu%22', 'promoted_content': None, 'query': '%22%C3%B6rg%C3%BCtde%C4%9Fil+arkada%C5%9Fgrubu%22', 'tweet_volume': None}, {'name': 'グレア', 'url': 'http://twitter.com/search?q=%E3%82%B0%E3%83%AC%E3%82%A2', 'promoted_content': None, 'query': '%E3%82%B0%E3%83%AC%E3%82%A2', 'tweet_volume': 23485}, {'name': '東京・池袋衝突事故', 'url': 'http://twitter.com/search?q=%E6%9D%B1%E4%BA%AC%E3%83%BB%E6%B1%A0%E8%A2%8B%E8%A1%9D%E7%AA%81%E4%BA%8B%E6%95%85', 'promoted_content': None, 'query': '%E6%9D%B1%E4%BA%AC%E3%83%BB%E6%B1%A0%E8%A2%8B%E8%A1%9D%E7%AA%81%E4%BA%8B%E6%95%85', 'tweet_volume': None}, {'name': '重体の女性と女児', 'url': 'http://twitter.com/search?q=%E9%87%8D%E4%BD%93%E3%81%AE%E5%A5%B3%E6%80%A7%E3%81%A8%E5%A5%B3%E5%85%90', 'promoted_content': None, 'query': '%E9%87%8D%E4%BD%93%E3%81%AE%E5%A5%B3%E6%80%A7%E3%81%A8%E5%A5%B3%E5%85%90', 'tweet_volume': None}, {'name': 'Lil Dicky', 'url': 'http://twitter.com/search?q=%22Lil+Dicky%22', 'promoted_content': None, 'query': '%22Lil+Dicky%22', 'tweet_volume': 42461}, {'name': '歩行者', 'url': 'http://twitter.com/search?q=%E6%AD%A9%E8%A1%8C%E8%80%85', 'promoted_content': None, 'query': '%E6%AD%A9%E8%A1%8C%E8%80%85', 'tweet_volume': 25405}, {'name': 'Derrick White', 'url': 'http://twitter.com/search?q=%22Derrick+White%22', 'promoted_content': None, 'query': '%22Derrick+White%22', 'tweet_volume': 27104}, {'name': '十二国記', 'url': 'http://twitter.com/search?q=%E5%8D%81%E4%BA%8C%E5%9B%BD%E8%A8%98', 'promoted_content': None, 'query': '%E5%8D%81%E4%BA%8C%E5%9B%BD%E8%A8%98', 'tweet_volume': 46803}, {'name': '#KpuJanganCurang', 'url': 'http://twitter.com/search?q=%23KpuJanganCurang', 'promoted_content': None, 'query': '%23KpuJanganCurang', 'tweet_volume': 75384}, {'name': '#HayırlıCumalar', 'url': 'http://twitter.com/search?q=%23Hay%C4%B1rl%C4%B1Cumalar', 'promoted_content': None, 'query': '%23Hay%C4%B1rl%C4%B1Cumalar', 'tweet_volume': 19848}, {'name': '#HayırlıKandiller', 'url': 'http://twitter.com/search?q=%23Hay%C4%B1rl%C4%B1Kandiller', 'promoted_content': None, 'query': '%23Hay%C4%B1rl%C4%B1Kandiller', 'tweet_volume': None}, {'name': '#HanumanJayanti', 'url': 'http://twitter.com/search?q=%23HanumanJayanti', 'promoted_content': None, 'query': '%23HanumanJayanti', 'tweet_volume': 83138}, {'name': '#IndonesianElectionHeroes', 'url': 'http://twitter.com/search?q=%23IndonesianElectionHeroes', 'promoted_content': None, 'query': '%23IndonesianElectionHeroes', 'tweet_volume': 19664}, {'name': '#يوم_الجمعه', 'url': 'http://twitter.com/search?q=%23%D9%8A%D9%88%D9%85_%D8%A7%D9%84%D8%AC%D9%85%D8%B9%D9%87', 'promoted_content': None, 'query': '%23%D9%8A%D9%88%D9%85_%D8%A7%D9%84%D8%AC%D9%85%D8%B9%D9%87', 'tweet_volume': 80799}, {'name': '#NRLBulldogsSouths', 'url': 'http://twitter.com/search?q=%23NRLBulldogsSouths', 'promoted_content': None, 'query': '%23NRLBulldogsSouths', 'tweet_volume': None}, {'name': '#NikahUmurBerapa', 'url': 'http://twitter.com/search?q=%23NikahUmurBerapa', 'promoted_content': None, 'query': '%23NikahUmurBerapa', 'tweet_volume': None}, {'name': '#DragRace', 'url': 'http://twitter.com/search?q=%23DragRace', 'promoted_content': None, 'query': '%23DragRace', 'tweet_volume': 37166}, {'name': '#ViernesSanto', 'url': 'http://twitter.com/search?q=%23ViernesSanto', 'promoted_content': None, 'query': '%23ViernesSanto', 'tweet_volume': None}, {'name': '#HardikPatel', 'url': 'http://twitter.com/search?q=%23HardikPatel', 'promoted_content': None, 'query': '%23HardikPatel', 'tweet_volume': None}, {'name': '#BLACKPINKxCorden', 'url': 'http://twitter.com/search?q=%23BLACKPINKxCorden', 'promoted_content': None, 'query': '%23BLACKPINKxCorden', 'tweet_volume': 253605}, {'name': '#Ontas', 'url': 'http://twitter.com/search?q=%23Ontas', 'promoted_content': None, 'query': '%23Ontas', 'tweet_volume': 27924}, {'name': '#ConCalmaRemix', 'url': 'http://twitter.com/search?q=%23ConCalmaRemix', 'promoted_content': None, 'query': '%23ConCalmaRemix', 'tweet_volume': 37846}, {'name': '#ProtestoEdiyorum', 'url': 'http://twitter.com/search?q=%23ProtestoEdiyorum', 'promoted_content': None, 'query': '%23ProtestoEdiyorum', 'tweet_volume': None}, {'name': '#DinahJane1', 'url': 'http://twitter.com/search?q=%23DinahJane1', 'promoted_content': None, 'query': '%23DinahJane1', 'tweet_volume': 23757}, {'name': '#ShivSena', 'url': 'http://twitter.com/search?q=%23ShivSena', 'promoted_content': None, 'query': '%23ShivSena', 'tweet_volume': None}, {'name': '#DuyguAsena', 'url': 'http://twitter.com/search?q=%23DuyguAsena', 'promoted_content': None, 'query': '%23DuyguAsena', 'tweet_volume': None}, {'name': '#TheJudasInMyLife', 'url': 'http://twitter.com/search?q=%23TheJudasInMyLife', 'promoted_content': None, 'query': '%23TheJudasInMyLife', 'tweet_volume': None}, {'name': '#Jersey', 'url': 'http://twitter.com/search?q=%23Jersey', 'promoted_content': None, 'query': '%23Jersey', 'tweet_volume': 20509}, {'name': '#اغلاق_BBM', 'url': 'http://twitter.com/search?q=%23%D8%A7%D8%BA%D9%84%D8%A7%D9%82_BBM', 'promoted_content': None, 'query': '%23%D8%A7%D8%BA%D9%84%D8%A7%D9%82_BBM', 'tweet_volume': 17055}, {'name': '#19aprile', 'url': 'http://twitter.com/search?q=%2319aprile', 'promoted_content': None, 'query': '%2319aprile', 'tweet_volume': None}, {'name': '#CHIvLIO', 'url': 'http://twitter.com/search?q=%23CHIvLIO', 'promoted_content': None, 'query': '%23CHIvLIO', 'tweet_volume': None}, {'name': '#Karfreitag', 'url': 'http://twitter.com/search?q=%23Karfreitag', 'promoted_content': None, 'query': '%23Karfreitag', 'tweet_volume': None}, {'name': '#JunquerasACN', 'url': 'http://twitter.com/search?q=%23JunquerasACN', 'promoted_content': None, 'query': '%23JunquerasACN', 'tweet_volume': None}], 'as_of': '2019-04-19T08:43:43Z', 'created_at': '2019-04-19T08:39:15Z', 'locations': [{'name': 'Worldwide', 'woeid': 1}]}]
[{'trends': [{'name': '#WeLoveTheEarth', 'url': 'http://twitter.com/search?q=%23WeLoveTheEarth', 'promoted_content': None, 'query': '%23WeLoveTheEarth', 'tweet_volume': 159698}, {'name': '#DragRace', 'url': 'http://twitter.com/search?q=%23DragRace', 'promoted_content': None, 'query': '%23DragRace', 'tweet_volume': 37166}, {'name': 'Lil Dicky', 'url': 'http://twitter.com/search?q=%22Lil+Dicky%22', 'promoted_content': None, 'query': '%22Lil+Dicky%22', 'tweet_volume': 42461}, {'name': 'Derrick White', 'url': 'http://twitter.com/search?q=%22Derrick+White%22', 'promoted_content': None, 'query': '%22Derrick+White%22', 'tweet_volume': 27104}, {'name': '#CUZILOVEYOU', 'url': 'http://twitter.com/search?q=%23CUZILOVEYOU', 'promoted_content': None, 'query': '%23CUZILOVEYOU', 'tweet_volume': None}, {'name': 'Kevin Durant', 'url': 'http://twitter.com/search?q=%22Kevin+Durant%22', 'promoted_content': None, 'query': '%22Kevin+Durant%22', 'tweet_volume': 21870}, {'name': '#StarTrekDiscovery', 'url': 'http://twitter.com/search?q=%23StarTrekDiscovery', 'promoted_content': None, 'query': '%23StarTrekDiscovery', 'tweet_volume': None}, {'name': '#GSWvsLAC', 'url': 'http://twitter.com/search?q=%23GSWvsLAC', 'promoted_content': None, 'query': '%23GSWvsLAC', 'tweet_volume': None}, {'name': 'Oshie', 'url': 'http://twitter.com/search?q=Oshie', 'promoted_content': None, 'query': 'Oshie', 'tweet_volume': None}, {'name': 'Seth Abramson', 'url': 'http://twitter.com/search?q=%22Seth+Abramson%22', 'promoted_content': None, 'query': '%22Seth+Abramson%22', 'tweet_volume': None}, {'name': 'Lyra McKee', 'url': 'http://twitter.com/search?q=%22Lyra+McKee%22', 'promoted_content': None, 'query': '%22Lyra+McKee%22', 'tweet_volume': 17606}, {'name': 'Silky', 'url': 'http://twitter.com/search?q=Silky', 'promoted_content': None, 'query': 'Silky', 'tweet_volume': 12881}, {'name': 'Kazuo Koike', 'url': 'http://twitter.com/search?q=%22Kazuo+Koike%22', 'promoted_content': None, 'query': '%22Kazuo+Koike%22', 'tweet_volume': None}, {'name': 'Game 6', 'url': 'http://twitter.com/search?q=%22Game+6%22', 'promoted_content': None, 'query': '%22Game+6%22', 'tweet_volume': None}, {'name': 'Yvie', 'url': 'http://twitter.com/search?q=Yvie', 'promoted_content': None, 'query': 'Yvie', 'tweet_volume': 10680}, {'name': 'Gallant', 'url': 'http://twitter.com/search?q=Gallant', 'promoted_content': None, 'query': 'Gallant', 'tweet_volume': None}, {'name': 'Lone Wolf and Cub', 'url': 'http://twitter.com/search?q=%22Lone+Wolf+and+Cub%22', 'promoted_content': None, 'query': '%22Lone+Wolf+and+Cub%22', 'tweet_volume': None}, {'name': 'George Conway', 'url': 'http://twitter.com/search?q=%22George+Conway%22', 'promoted_content': None, 'query': '%22George+Conway%22', 'tweet_volume': 27458}, {'name': 'David Fletcher', 'url': 'http://twitter.com/search?q=%22David+Fletcher%22', 'promoted_content': None, 'query': '%22David+Fletcher%22', 'tweet_volume': None}, {'name': 'Derry', 'url': 'http://twitter.com/search?q=Derry', 'promoted_content': None, 'query': 'Derry', 'tweet_volume': 28234}, {'name': 'Mike Anderson', 'url': 'http://twitter.com/search?q=%22Mike+Anderson%22', 'promoted_content': None, 'query': '%22Mike+Anderson%22', 'tweet_volume': None}, {'name': 'Shy Glizzy', 'url': 'http://twitter.com/search?q=%22Shy+Glizzy%22', 'promoted_content': None, 'query': '%22Shy+Glizzy%22', 'tweet_volume': None}, {'name': 'Tomas Hertl', 'url': 'http://twitter.com/search?q=%22Tomas+Hertl%22', 'promoted_content': None, 'query': '%22Tomas+Hertl%22', 'tweet_volume': None}, {'name': 'Servais', 'url': 'http://twitter.com/search?q=Servais', 'promoted_content': None, 'query': 'Servais', 'tweet_volume': None}, {'name': 'WE LOVE THE EARTH', 'url': 'http://twitter.com/search?q=%22WE+LOVE+THE+EARTH%22', 'promoted_content': None, 'query': '%22WE+LOVE+THE+EARTH%22', 'tweet_volume': None}, {'name': '"Earth"', 'url': 'http://twitter.com/search?q=%22Earth%22', 'promoted_content': None, 'query': '%22Earth%22', 'tweet_volume': 338417}, {'name': '#DinahJane1', 'url': 'http://twitter.com/search?q=%23DinahJane1', 'promoted_content': None, 'query': '%23DinahJane1', 'tweet_volume': 23757}, {'name': '#WhatStopsYouFromGoingHome', 'url': 'http://twitter.com/search?q=%23WhatStopsYouFromGoingHome', 'promoted_content': None, 'query': '%23WhatStopsYouFromGoingHome', 'tweet_volume': None}, {'name': '#MakeAMovieSensual', 'url': 'http://twitter.com/search?q=%23MakeAMovieSensual', 'promoted_content': None, 'query': '%23MakeAMovieSensual', 'tweet_volume': None}, {'name': '#DontChangeOutNow', 'url': 'http://twitter.com/search?q=%23DontChangeOutNow', 'promoted_content': None, 'query': '%23DontChangeOutNow', 'tweet_volume': None}, {'name': '#BLACKPINKxCorden', 'url': 'http://twitter.com/search?q=%23BLACKPINKxCorden', 'promoted_content': None, 'query': '%23BLACKPINKxCorden', 'tweet_volume': 253605}, {'name': '#WorldofWarcraftMains', 'url': 'http://twitter.com/search?q=%23WorldofWarcraftMains', 'promoted_content': None, 'query': '%23WorldofWarcraftMains', 'tweet_volume': None}, {'name': '#MyDrunkUncleSays', 'url': 'http://twitter.com/search?q=%23MyDrunkUncleSays', 'promoted_content': None, 'query': '%23MyDrunkUncleSays', 'tweet_volume': None}, {'name': '#WGAMIX', 'url': 'http://twitter.com/search?q=%23WGAMIX', 'promoted_content': None, 'query': '%23WGAMIX', 'tweet_volume': None}, {'name': '#Earth', 'url': 'http://twitter.com/search?q=%23Earth', 'promoted_content': None, 'query': '%23Earth', 'tweet_volume': 13655}, {'name': '#TheLegendOfVoxMachina', 'url': 'http://twitter.com/search?q=%23TheLegendOfVoxMachina', 'promoted_content': None, 'query': '%23TheLegendOfVoxMachina', 'tweet_volume': None}, {'name': '#AFLNorthDons', 'url': 'http://twitter.com/search?q=%23AFLNorthDons', 'promoted_content': None, 'query': '%23AFLNorthDons', 'tweet_volume': None}, {'name': '#FridayFeeling', 'url': 'http://twitter.com/search?q=%23FridayFeeling', 'promoted_content': None, 'query': '%23FridayFeeling', 'tweet_volume': 19510}, {'name': '#MyInnerDemonSaid', 'url': 'http://twitter.com/search?q=%23MyInnerDemonSaid', 'promoted_content': None, 'query': '%23MyInnerDemonSaid', 'tweet_volume': None}, {'name': '#rupaulsdragrace', 'url': 'http://twitter.com/search?q=%23rupaulsdragrace', 'promoted_content': None, 'query': '%23rupaulsdragrace', 'tweet_volume': None}, {'name': '#ConCalmaRemix', 'url': 'http://twitter.com/search?q=%23ConCalmaRemix', 'promoted_content': None, 'query': '%23ConCalmaRemix', 'tweet_volume': 37846}, {'name': '#TimeToImpeach', 'url': 'http://twitter.com/search?q=%23TimeToImpeach', 'promoted_content': None, 'query': '%23TimeToImpeach', 'tweet_volume': 21732}, {'name': '#NRLBulldogsSouths', 'url': 'http://twitter.com/search?q=%23NRLBulldogsSouths', 'promoted_content': None, 'query': '%23NRLBulldogsSouths', 'tweet_volume': None}, {'name': '#CriticalRoleSpoilers', 'url': 'http://twitter.com/search?q=%23CriticalRoleSpoilers', 'promoted_content': None, 'query': '%23CriticalRoleSpoilers', 'tweet_volume': None}, {'name': '#GossipShouldBe', 'url': 'http://twitter.com/search?q=%23GossipShouldBe', 'promoted_content': None, 'query': '%23GossipShouldBe', 'tweet_volume': None}, {'name': '#LilDicky', 'url': 'http://twitter.com/search?q=%23LilDicky', 'promoted_content': None, 'query': '%23LilDicky', 'tweet_volume': None}, {'name': '#RPDR', 'url': 'http://twitter.com/search?q=%23RPDR', 'promoted_content': None, 'query': '%23RPDR', 'tweet_volume': None}, {'name': '#WeirdDateStories', 'url': 'http://twitter.com/search?q=%23WeirdDateStories', 'promoted_content': None, 'query': '%23WeirdDateStories', 'tweet_volume': None}, {'name': '#HustleAndSoul', 'url': 'http://twitter.com/search?q=%23HustleAndSoul', 'promoted_content': None, 'query': '%23HustleAndSoul', 'tweet_volume': None}, {'name': '#fridaymotivation', 'url': 'http://twitter.com/search?q=%23fridaymotivation', 'promoted_content': None, 'query': '%23fridaymotivation', 'tweet_volume': None}], 'as_of': '2019-04-19T08:43:43Z', 'created_at': '2019-04-19T08:39:15Z', 'locations': [{'name': 'United States', 'woeid': 23424977}]}]
In [13]:
%%nose

# One or more tests of the student's code
# The @solution should pass the tests
# The purpose of the tests is to try to catch common errors and
# to give the student a hint on how to resolve these errors

def test_pandas_loaded():
    assert 'json' in globals(), \
    'Did you import the json module?'
    
def test_WW_trends_correctly_loaded():
    correct_ww_trends = json.loads(open('datasets/WWTrends.json').read())
    assert correct_ww_trends == WW_trends, "The variable WW_trends should contain the data in WWTrends.json."

def test_US_trends_correctly_loaded():
    correct_us_trends = json.loads(open('datasets/USTrends.json').read())
    assert correct_us_trends == US_trends, "The variable WW_trends should contain the data in USTrends.json."
Out[13]:
3/3 tests passed

2. Prettifying the output

Our data was hard to read! Luckily, we can resort to the json.dumps() method to have it formatted as a pretty JSON string.

In [2]:
# Pretty-printing the results. First WW and then US trends. 

print("WW trends:")
print (json.dumps(WW_trends, indent=1))

print("\n", "US trends:")
print (json.dumps(US_trends, indent=1))
WW trends:
[
 {
  "trends": [
   {
    "name": "#BeratKandili",
    "url": "http://twitter.com/search?q=%23BeratKandili",
    "promoted_content": null,
    "query": "%23BeratKandili",
    "tweet_volume": 46373
   },
   {
    "name": "#GoodFriday",
    "url": "http://twitter.com/search?q=%23GoodFriday",
    "promoted_content": null,
    "query": "%23GoodFriday",
    "tweet_volume": 81891
   },
   {
    "name": "#WeLoveTheEarth",
    "url": "http://twitter.com/search?q=%23WeLoveTheEarth",
    "promoted_content": null,
    "query": "%23WeLoveTheEarth",
    "tweet_volume": 159698
   },
   {
    "name": "#195TLdenTTVerilir",
    "url": "http://twitter.com/search?q=%23195TLdenTTVerilir",
    "promoted_content": null,
    "query": "%23195TLdenTTVerilir",
    "tweet_volume": null
   },
   {
    "name": "#AFLNorthDons",
    "url": "http://twitter.com/search?q=%23AFLNorthDons",
    "promoted_content": null,
    "query": "%23AFLNorthDons",
    "tweet_volume": null
   },
   {
    "name": "Shiv Sena",
    "url": "http://twitter.com/search?q=%22Shiv+Sena%22",
    "promoted_content": null,
    "query": "%22Shiv+Sena%22",
    "tweet_volume": null
   },
   {
    "name": "Lyra McKee",
    "url": "http://twitter.com/search?q=%22Lyra+McKee%22",
    "promoted_content": null,
    "query": "%22Lyra+McKee%22",
    "tweet_volume": 17606
   },
   {
    "name": "Priyanka Chaturvedi",
    "url": "http://twitter.com/search?q=%22Priyanka+Chaturvedi%22",
    "promoted_content": null,
    "query": "%22Priyanka+Chaturvedi%22",
    "tweet_volume": 22342
   },
   {
    "name": "Derry",
    "url": "http://twitter.com/search?q=Derry",
    "promoted_content": null,
    "query": "Derry",
    "tweet_volume": 28234
   },
   {
    "name": "\u6c60\u888b\u306e\u4e8b\u6545",
    "url": "http://twitter.com/search?q=%E6%B1%A0%E8%A2%8B%E3%81%AE%E4%BA%8B%E6%95%85",
    "promoted_content": null,
    "query": "%E6%B1%A0%E8%A2%8B%E3%81%AE%E4%BA%8B%E6%95%85",
    "tweet_volume": 34381
   },
   {
    "name": "\u30d7\u30ea\u30a6\u30b9",
    "url": "http://twitter.com/search?q=%E3%83%97%E3%83%AA%E3%82%A6%E3%82%B9",
    "promoted_content": null,
    "query": "%E3%83%97%E3%83%AA%E3%82%A6%E3%82%B9",
    "tweet_volume": 22944
   },
   {
    "name": "Hemant Karkare",
    "url": "http://twitter.com/search?q=%22Hemant+Karkare%22",
    "promoted_content": null,
    "query": "%22Hemant+Karkare%22",
    "tweet_volume": 24067
   },
   {
    "name": "\u9ad8\u9f62\u8005",
    "url": "http://twitter.com/search?q=%E9%AB%98%E9%BD%A2%E8%80%85",
    "promoted_content": null,
    "query": "%E9%AB%98%E9%BD%A2%E8%80%85",
    "tweet_volume": 28382
   },
   {
    "name": "\ube0c\uc774\uc54c",
    "url": "http://twitter.com/search?q=%EB%B8%8C%EC%9D%B4%EC%95%8C",
    "promoted_content": null,
    "query": "%EB%B8%8C%EC%9D%B4%EC%95%8C",
    "tweet_volume": 15490
   },
   {
    "name": "\u5200\u30b9\u30c6",
    "url": "http://twitter.com/search?q=%E5%88%80%E3%82%B9%E3%83%86",
    "promoted_content": null,
    "query": "%E5%88%80%E3%82%B9%E3%83%86",
    "tweet_volume": null
   },
   {
    "name": "\u514d\u8a31\u8fd4\u7d0d",
    "url": "http://twitter.com/search?q=%E5%85%8D%E8%A8%B1%E8%BF%94%E7%B4%8D",
    "promoted_content": null,
    "query": "%E5%85%8D%E8%A8%B1%E8%BF%94%E7%B4%8D",
    "tweet_volume": null
   },
   {
    "name": "Berat Kandilimiz",
    "url": "http://twitter.com/search?q=%22Berat+Kandilimiz%22",
    "promoted_content": null,
    "query": "%22Berat+Kandilimiz%22",
    "tweet_volume": 10901
   },
   {
    "name": "\u00f6rg\u00fctde\u011fil arkada\u015fgrubu",
    "url": "http://twitter.com/search?q=%22%C3%B6rg%C3%BCtde%C4%9Fil+arkada%C5%9Fgrubu%22",
    "promoted_content": null,
    "query": "%22%C3%B6rg%C3%BCtde%C4%9Fil+arkada%C5%9Fgrubu%22",
    "tweet_volume": null
   },
   {
    "name": "\u30b0\u30ec\u30a2",
    "url": "http://twitter.com/search?q=%E3%82%B0%E3%83%AC%E3%82%A2",
    "promoted_content": null,
    "query": "%E3%82%B0%E3%83%AC%E3%82%A2",
    "tweet_volume": 23485
   },
   {
    "name": "\u6771\u4eac\u30fb\u6c60\u888b\u885d\u7a81\u4e8b\u6545",
    "url": "http://twitter.com/search?q=%E6%9D%B1%E4%BA%AC%E3%83%BB%E6%B1%A0%E8%A2%8B%E8%A1%9D%E7%AA%81%E4%BA%8B%E6%95%85",
    "promoted_content": null,
    "query": "%E6%9D%B1%E4%BA%AC%E3%83%BB%E6%B1%A0%E8%A2%8B%E8%A1%9D%E7%AA%81%E4%BA%8B%E6%95%85",
    "tweet_volume": null
   },
   {
    "name": "\u91cd\u4f53\u306e\u5973\u6027\u3068\u5973\u5150",
    "url": "http://twitter.com/search?q=%E9%87%8D%E4%BD%93%E3%81%AE%E5%A5%B3%E6%80%A7%E3%81%A8%E5%A5%B3%E5%85%90",
    "promoted_content": null,
    "query": "%E9%87%8D%E4%BD%93%E3%81%AE%E5%A5%B3%E6%80%A7%E3%81%A8%E5%A5%B3%E5%85%90",
    "tweet_volume": null
   },
   {
    "name": "Lil Dicky",
    "url": "http://twitter.com/search?q=%22Lil+Dicky%22",
    "promoted_content": null,
    "query": "%22Lil+Dicky%22",
    "tweet_volume": 42461
   },
   {
    "name": "\u6b69\u884c\u8005",
    "url": "http://twitter.com/search?q=%E6%AD%A9%E8%A1%8C%E8%80%85",
    "promoted_content": null,
    "query": "%E6%AD%A9%E8%A1%8C%E8%80%85",
    "tweet_volume": 25405
   },
   {
    "name": "Derrick White",
    "url": "http://twitter.com/search?q=%22Derrick+White%22",
    "promoted_content": null,
    "query": "%22Derrick+White%22",
    "tweet_volume": 27104
   },
   {
    "name": "\u5341\u4e8c\u56fd\u8a18",
    "url": "http://twitter.com/search?q=%E5%8D%81%E4%BA%8C%E5%9B%BD%E8%A8%98",
    "promoted_content": null,
    "query": "%E5%8D%81%E4%BA%8C%E5%9B%BD%E8%A8%98",
    "tweet_volume": 46803
   },
   {
    "name": "#KpuJanganCurang",
    "url": "http://twitter.com/search?q=%23KpuJanganCurang",
    "promoted_content": null,
    "query": "%23KpuJanganCurang",
    "tweet_volume": 75384
   },
   {
    "name": "#Hay\u0131rl\u0131Cumalar",
    "url": "http://twitter.com/search?q=%23Hay%C4%B1rl%C4%B1Cumalar",
    "promoted_content": null,
    "query": "%23Hay%C4%B1rl%C4%B1Cumalar",
    "tweet_volume": 19848
   },
   {
    "name": "#Hay\u0131rl\u0131Kandiller",
    "url": "http://twitter.com/search?q=%23Hay%C4%B1rl%C4%B1Kandiller",
    "promoted_content": null,
    "query": "%23Hay%C4%B1rl%C4%B1Kandiller",
    "tweet_volume": null
   },
   {
    "name": "#HanumanJayanti",
    "url": "http://twitter.com/search?q=%23HanumanJayanti",
    "promoted_content": null,
    "query": "%23HanumanJayanti",
    "tweet_volume": 83138
   },
   {
    "name": "#IndonesianElectionHeroes",
    "url": "http://twitter.com/search?q=%23IndonesianElectionHeroes",
    "promoted_content": null,
    "query": "%23IndonesianElectionHeroes",
    "tweet_volume": 19664
   },
   {
    "name": "#\u064a\u0648\u0645_\u0627\u0644\u062c\u0645\u0639\u0647",
    "url": "http://twitter.com/search?q=%23%D9%8A%D9%88%D9%85_%D8%A7%D9%84%D8%AC%D9%85%D8%B9%D9%87",
    "promoted_content": null,
    "query": "%23%D9%8A%D9%88%D9%85_%D8%A7%D9%84%D8%AC%D9%85%D8%B9%D9%87",
    "tweet_volume": 80799
   },
   {
    "name": "#NRLBulldogsSouths",
    "url": "http://twitter.com/search?q=%23NRLBulldogsSouths",
    "promoted_content": null,
    "query": "%23NRLBulldogsSouths",
    "tweet_volume": null
   },
   {
    "name": "#NikahUmurBerapa",
    "url": "http://twitter.com/search?q=%23NikahUmurBerapa",
    "promoted_content": null,
    "query": "%23NikahUmurBerapa",
    "tweet_volume": null
   },
   {
    "name": "#DragRace",
    "url": "http://twitter.com/search?q=%23DragRace",
    "promoted_content": null,
    "query": "%23DragRace",
    "tweet_volume": 37166
   },
   {
    "name": "#ViernesSanto",
    "url": "http://twitter.com/search?q=%23ViernesSanto",
    "promoted_content": null,
    "query": "%23ViernesSanto",
    "tweet_volume": null
   },
   {
    "name": "#HardikPatel",
    "url": "http://twitter.com/search?q=%23HardikPatel",
    "promoted_content": null,
    "query": "%23HardikPatel",
    "tweet_volume": null
   },
   {
    "name": "#BLACKPINKxCorden",
    "url": "http://twitter.com/search?q=%23BLACKPINKxCorden",
    "promoted_content": null,
    "query": "%23BLACKPINKxCorden",
    "tweet_volume": 253605
   },
   {
    "name": "#Ontas",
    "url": "http://twitter.com/search?q=%23Ontas",
    "promoted_content": null,
    "query": "%23Ontas",
    "tweet_volume": 27924
   },
   {
    "name": "#ConCalmaRemix",
    "url": "http://twitter.com/search?q=%23ConCalmaRemix",
    "promoted_content": null,
    "query": "%23ConCalmaRemix",
    "tweet_volume": 37846
   },
   {
    "name": "#ProtestoEdiyorum",
    "url": "http://twitter.com/search?q=%23ProtestoEdiyorum",
    "promoted_content": null,
    "query": "%23ProtestoEdiyorum",
    "tweet_volume": null
   },
   {
    "name": "#DinahJane1",
    "url": "http://twitter.com/search?q=%23DinahJane1",
    "promoted_content": null,
    "query": "%23DinahJane1",
    "tweet_volume": 23757
   },
   {
    "name": "#ShivSena",
    "url": "http://twitter.com/search?q=%23ShivSena",
    "promoted_content": null,
    "query": "%23ShivSena",
    "tweet_volume": null
   },
   {
    "name": "#DuyguAsena",
    "url": "http://twitter.com/search?q=%23DuyguAsena",
    "promoted_content": null,
    "query": "%23DuyguAsena",
    "tweet_volume": null
   },
   {
    "name": "#TheJudasInMyLife",
    "url": "http://twitter.com/search?q=%23TheJudasInMyLife",
    "promoted_content": null,
    "query": "%23TheJudasInMyLife",
    "tweet_volume": null
   },
   {
    "name": "#Jersey",
    "url": "http://twitter.com/search?q=%23Jersey",
    "promoted_content": null,
    "query": "%23Jersey",
    "tweet_volume": 20509
   },
   {
    "name": "#\u0627\u063a\u0644\u0627\u0642_BBM",
    "url": "http://twitter.com/search?q=%23%D8%A7%D8%BA%D9%84%D8%A7%D9%82_BBM",
    "promoted_content": null,
    "query": "%23%D8%A7%D8%BA%D9%84%D8%A7%D9%82_BBM",
    "tweet_volume": 17055
   },
   {
    "name": "#19aprile",
    "url": "http://twitter.com/search?q=%2319aprile",
    "promoted_content": null,
    "query": "%2319aprile",
    "tweet_volume": null
   },
   {
    "name": "#CHIvLIO",
    "url": "http://twitter.com/search?q=%23CHIvLIO",
    "promoted_content": null,
    "query": "%23CHIvLIO",
    "tweet_volume": null
   },
   {
    "name": "#Karfreitag",
    "url": "http://twitter.com/search?q=%23Karfreitag",
    "promoted_content": null,
    "query": "%23Karfreitag",
    "tweet_volume": null
   },
   {
    "name": "#JunquerasACN",
    "url": "http://twitter.com/search?q=%23JunquerasACN",
    "promoted_content": null,
    "query": "%23JunquerasACN",
    "tweet_volume": null
   }
  ],
  "as_of": "2019-04-19T08:43:43Z",
  "created_at": "2019-04-19T08:39:15Z",
  "locations": [
   {
    "name": "Worldwide",
    "woeid": 1
   }
  ]
 }
]

 US trends:
[
 {
  "trends": [
   {
    "name": "#WeLoveTheEarth",
    "url": "http://twitter.com/search?q=%23WeLoveTheEarth",
    "promoted_content": null,
    "query": "%23WeLoveTheEarth",
    "tweet_volume": 159698
   },
   {
    "name": "#DragRace",
    "url": "http://twitter.com/search?q=%23DragRace",
    "promoted_content": null,
    "query": "%23DragRace",
    "tweet_volume": 37166
   },
   {
    "name": "Lil Dicky",
    "url": "http://twitter.com/search?q=%22Lil+Dicky%22",
    "promoted_content": null,
    "query": "%22Lil+Dicky%22",
    "tweet_volume": 42461
   },
   {
    "name": "Derrick White",
    "url": "http://twitter.com/search?q=%22Derrick+White%22",
    "promoted_content": null,
    "query": "%22Derrick+White%22",
    "tweet_volume": 27104
   },
   {
    "name": "#CUZILOVEYOU",
    "url": "http://twitter.com/search?q=%23CUZILOVEYOU",
    "promoted_content": null,
    "query": "%23CUZILOVEYOU",
    "tweet_volume": null
   },
   {
    "name": "Kevin Durant",
    "url": "http://twitter.com/search?q=%22Kevin+Durant%22",
    "promoted_content": null,
    "query": "%22Kevin+Durant%22",
    "tweet_volume": 21870
   },
   {
    "name": "#StarTrekDiscovery",
    "url": "http://twitter.com/search?q=%23StarTrekDiscovery",
    "promoted_content": null,
    "query": "%23StarTrekDiscovery",
    "tweet_volume": null
   },
   {
    "name": "#GSWvsLAC",
    "url": "http://twitter.com/search?q=%23GSWvsLAC",
    "promoted_content": null,
    "query": "%23GSWvsLAC",
    "tweet_volume": null
   },
   {
    "name": "Oshie",
    "url": "http://twitter.com/search?q=Oshie",
    "promoted_content": null,
    "query": "Oshie",
    "tweet_volume": null
   },
   {
    "name": "Seth Abramson",
    "url": "http://twitter.com/search?q=%22Seth+Abramson%22",
    "promoted_content": null,
    "query": "%22Seth+Abramson%22",
    "tweet_volume": null
   },
   {
    "name": "Lyra McKee",
    "url": "http://twitter.com/search?q=%22Lyra+McKee%22",
    "promoted_content": null,
    "query": "%22Lyra+McKee%22",
    "tweet_volume": 17606
   },
   {
    "name": "Silky",
    "url": "http://twitter.com/search?q=Silky",
    "promoted_content": null,
    "query": "Silky",
    "tweet_volume": 12881
   },
   {
    "name": "Kazuo Koike",
    "url": "http://twitter.com/search?q=%22Kazuo+Koike%22",
    "promoted_content": null,
    "query": "%22Kazuo+Koike%22",
    "tweet_volume": null
   },
   {
    "name": "Game 6",
    "url": "http://twitter.com/search?q=%22Game+6%22",
    "promoted_content": null,
    "query": "%22Game+6%22",
    "tweet_volume": null
   },
   {
    "name": "Yvie",
    "url": "http://twitter.com/search?q=Yvie",
    "promoted_content": null,
    "query": "Yvie",
    "tweet_volume": 10680
   },
   {
    "name": "Gallant",
    "url": "http://twitter.com/search?q=Gallant",
    "promoted_content": null,
    "query": "Gallant",
    "tweet_volume": null
   },
   {
    "name": "Lone Wolf and Cub",
    "url": "http://twitter.com/search?q=%22Lone+Wolf+and+Cub%22",
    "promoted_content": null,
    "query": "%22Lone+Wolf+and+Cub%22",
    "tweet_volume": null
   },
   {
    "name": "George Conway",
    "url": "http://twitter.com/search?q=%22George+Conway%22",
    "promoted_content": null,
    "query": "%22George+Conway%22",
    "tweet_volume": 27458
   },
   {
    "name": "David Fletcher",
    "url": "http://twitter.com/search?q=%22David+Fletcher%22",
    "promoted_content": null,
    "query": "%22David+Fletcher%22",
    "tweet_volume": null
   },
   {
    "name": "Derry",
    "url": "http://twitter.com/search?q=Derry",
    "promoted_content": null,
    "query": "Derry",
    "tweet_volume": 28234
   },
   {
    "name": "Mike Anderson",
    "url": "http://twitter.com/search?q=%22Mike+Anderson%22",
    "promoted_content": null,
    "query": "%22Mike+Anderson%22",
    "tweet_volume": null
   },
   {
    "name": "Shy Glizzy",
    "url": "http://twitter.com/search?q=%22Shy+Glizzy%22",
    "promoted_content": null,
    "query": "%22Shy+Glizzy%22",
    "tweet_volume": null
   },
   {
    "name": "Tomas Hertl",
    "url": "http://twitter.com/search?q=%22Tomas+Hertl%22",
    "promoted_content": null,
    "query": "%22Tomas+Hertl%22",
    "tweet_volume": null
   },
   {
    "name": "Servais",
    "url": "http://twitter.com/search?q=Servais",
    "promoted_content": null,
    "query": "Servais",
    "tweet_volume": null
   },
   {
    "name": "WE LOVE THE EARTH",
    "url": "http://twitter.com/search?q=%22WE+LOVE+THE+EARTH%22",
    "promoted_content": null,
    "query": "%22WE+LOVE+THE+EARTH%22",
    "tweet_volume": null
   },
   {
    "name": "\"Earth\"",
    "url": "http://twitter.com/search?q=%22Earth%22",
    "promoted_content": null,
    "query": "%22Earth%22",
    "tweet_volume": 338417
   },
   {
    "name": "#DinahJane1",
    "url": "http://twitter.com/search?q=%23DinahJane1",
    "promoted_content": null,
    "query": "%23DinahJane1",
    "tweet_volume": 23757
   },
   {
    "name": "#WhatStopsYouFromGoingHome",
    "url": "http://twitter.com/search?q=%23WhatStopsYouFromGoingHome",
    "promoted_content": null,
    "query": "%23WhatStopsYouFromGoingHome",
    "tweet_volume": null
   },
   {
    "name": "#MakeAMovieSensual",
    "url": "http://twitter.com/search?q=%23MakeAMovieSensual",
    "promoted_content": null,
    "query": "%23MakeAMovieSensual",
    "tweet_volume": null
   },
   {
    "name": "#DontChangeOutNow",
    "url": "http://twitter.com/search?q=%23DontChangeOutNow",
    "promoted_content": null,
    "query": "%23DontChangeOutNow",
    "tweet_volume": null
   },
   {
    "name": "#BLACKPINKxCorden",
    "url": "http://twitter.com/search?q=%23BLACKPINKxCorden",
    "promoted_content": null,
    "query": "%23BLACKPINKxCorden",
    "tweet_volume": 253605
   },
   {
    "name": "#WorldofWarcraftMains",
    "url": "http://twitter.com/search?q=%23WorldofWarcraftMains",
    "promoted_content": null,
    "query": "%23WorldofWarcraftMains",
    "tweet_volume": null
   },
   {
    "name": "#MyDrunkUncleSays",
    "url": "http://twitter.com/search?q=%23MyDrunkUncleSays",
    "promoted_content": null,
    "query": "%23MyDrunkUncleSays",
    "tweet_volume": null
   },
   {
    "name": "#WGAMIX",
    "url": "http://twitter.com/search?q=%23WGAMIX",
    "promoted_content": null,
    "query": "%23WGAMIX",
    "tweet_volume": null
   },
   {
    "name": "#Earth",
    "url": "http://twitter.com/search?q=%23Earth",
    "promoted_content": null,
    "query": "%23Earth",
    "tweet_volume": 13655
   },
   {
    "name": "#TheLegendOfVoxMachina",
    "url": "http://twitter.com/search?q=%23TheLegendOfVoxMachina",
    "promoted_content": null,
    "query": "%23TheLegendOfVoxMachina",
    "tweet_volume": null
   },
   {
    "name": "#AFLNorthDons",
    "url": "http://twitter.com/search?q=%23AFLNorthDons",
    "promoted_content": null,
    "query": "%23AFLNorthDons",
    "tweet_volume": null
   },
   {
    "name": "#FridayFeeling",
    "url": "http://twitter.com/search?q=%23FridayFeeling",
    "promoted_content": null,
    "query": "%23FridayFeeling",
    "tweet_volume": 19510
   },
   {
    "name": "#MyInnerDemonSaid",
    "url": "http://twitter.com/search?q=%23MyInnerDemonSaid",
    "promoted_content": null,
    "query": "%23MyInnerDemonSaid",
    "tweet_volume": null
   },
   {
    "name": "#rupaulsdragrace",
    "url": "http://twitter.com/search?q=%23rupaulsdragrace",
    "promoted_content": null,
    "query": "%23rupaulsdragrace",
    "tweet_volume": null
   },
   {
    "name": "#ConCalmaRemix",
    "url": "http://twitter.com/search?q=%23ConCalmaRemix",
    "promoted_content": null,
    "query": "%23ConCalmaRemix",
    "tweet_volume": 37846
   },
   {
    "name": "#TimeToImpeach",
    "url": "http://twitter.com/search?q=%23TimeToImpeach",
    "promoted_content": null,
    "query": "%23TimeToImpeach",
    "tweet_volume": 21732
   },
   {
    "name": "#NRLBulldogsSouths",
    "url": "http://twitter.com/search?q=%23NRLBulldogsSouths",
    "promoted_content": null,
    "query": "%23NRLBulldogsSouths",
    "tweet_volume": null
   },
   {
    "name": "#CriticalRoleSpoilers",
    "url": "http://twitter.com/search?q=%23CriticalRoleSpoilers",
    "promoted_content": null,
    "query": "%23CriticalRoleSpoilers",
    "tweet_volume": null
   },
   {
    "name": "#GossipShouldBe",
    "url": "http://twitter.com/search?q=%23GossipShouldBe",
    "promoted_content": null,
    "query": "%23GossipShouldBe",
    "tweet_volume": null
   },
   {
    "name": "#LilDicky",
    "url": "http://twitter.com/search?q=%23LilDicky",
    "promoted_content": null,
    "query": "%23LilDicky",
    "tweet_volume": null
   },
   {
    "name": "#RPDR",
    "url": "http://twitter.com/search?q=%23RPDR",
    "promoted_content": null,
    "query": "%23RPDR",
    "tweet_volume": null
   },
   {
    "name": "#WeirdDateStories",
    "url": "http://twitter.com/search?q=%23WeirdDateStories",
    "promoted_content": null,
    "query": "%23WeirdDateStories",
    "tweet_volume": null
   },
   {
    "name": "#HustleAndSoul",
    "url": "http://twitter.com/search?q=%23HustleAndSoul",
    "promoted_content": null,
    "query": "%23HustleAndSoul",
    "tweet_volume": null
   },
   {
    "name": "#fridaymotivation",
    "url": "http://twitter.com/search?q=%23fridaymotivation",
    "promoted_content": null,
    "query": "%23fridaymotivation",
    "tweet_volume": null
   }
  ],
  "as_of": "2019-04-19T08:43:43Z",
  "created_at": "2019-04-19T08:39:15Z",
  "locations": [
   {
    "name": "United States",
    "woeid": 23424977
   }
  ]
 }
]
In [15]:
%%nose
# %%nose needs to be included at the beginning of every @tests cell

# Not sure what to check here

# One or more tests of the students code. 
# The @solution should pass the tests.
# The purpose of the tests is to try to catch common errors and to 
# give the student a hint on how to resolve these errors.

def strip_comment_lines(cell_input):
    """Returns cell input string with comment lines removed."""
    return '\n'.join(line for line in cell_input.splitlines() if not line.startswith('#'))

last_input = strip_comment_lines(In[-2])

def test_info_command():
    assert 'json.dumps(WW_trends' in last_input, \
        "We expected the json.dumps method with the correct input object."
    assert 'json.dumps(US_trends' in last_input, \
         "We expected the json.dumps method with the correct input object."
Out[15]:
1/1 tests passed

🕵️‍♀️ From the pretty-printed results (output of the previous task), we can observe that:

  • We have an array of trend objects having: the name of the trending topic, the query parameter that can be used to search for the topic on Twitter-Search, the search URL and the volume of tweets for the last 24 hours, if available. (The trends get updated every 5 mins.)

  • At query time #BeratKandili, #GoodFriday and #WeLoveTheEarth were trending WW.

  • "tweet_volume" tell us that #WeLoveTheEarth was the most popular among the three.

  • Results are not sorted by "tweet_volume".

  • There are some trends which are unique to the US.


It’s easy to skim through the two sets of trends and spot common trends, but let's not do "manual" work. We can use Python’s set data structure to find common trends — we can iterate through the two trends objects, cast the lists of names to sets, and call the intersection method to get the common names between the two sets.

In [3]:
# Extracting all the WW trend names from WW_trends
world_trends = set([trend['name']                    
                    for trend in WW_trends[0]['trends']])

# Extracting all the US trend names from US_trends
us_trends = set([trend['name'] 
                     for trend in US_trends[0]['trends']]) 

# Let's get the intersection of the two sets of trends
common_trends = world_trends.intersection(us_trends)

# Inspecting the data
print(world_trends, "\n")
print(us_trends, "\n")
print (len(common_trends), "common trends:", common_trends)
{'東京・池袋衝突事故', '#DragRace', 'Lyra McKee', '#Jersey', '#Karfreitag', '#HayırlıCumalar', '#AFLNorthDons', '歩行者', '池袋の事故', 'Derrick White', '免許返納', '#HayırlıKandiller', '#IndonesianElectionHeroes', 'örgütdeğil arkadaşgrubu', '#يوم_الجمعه', '#195TLdenTTVerilir', 'グレア', '#ViernesSanto', '#ProtestoEdiyorum', '#BLACKPINKxCorden', '브이알', '#BeratKandili', '#ConCalmaRemix', '#CHIvLIO', 'Derry', '#WeLoveTheEarth', '重体の女性と女児', 'Shiv Sena', '十二国記', '#DinahJane1', '#Ontas', '#DuyguAsena', '#TheJudasInMyLife', '#GoodFriday', '刀ステ', 'Lil Dicky', '#JunquerasACN', '#KpuJanganCurang', '#HanumanJayanti', '高齢者', '#اغلاق_BBM', '#HardikPatel', 'プリウス', '#ShivSena', 'Hemant Karkare', 'Priyanka Chaturvedi', '#NRLBulldogsSouths', '#19aprile', '#NikahUmurBerapa', 'Berat Kandilimiz'} 

{'Mike Anderson', '#DragRace', 'Lyra McKee', 'Servais', '#MyInnerDemonSaid', '#AFLNorthDons', '#Earth', 'Derrick White', '#CUZILOVEYOU', 'Kazuo Koike', 'David Fletcher', '#DontChangeOutNow', '#RPDR', 'Shy Glizzy', '#WorldofWarcraftMains', '#StarTrekDiscovery', 'Tomas Hertl', '#LilDicky', '#rupaulsdragrace', '#BLACKPINKxCorden', '#GossipShouldBe', '#ConCalmaRemix', '#MyDrunkUncleSays', '#WGAMIX', '#TimeToImpeach', '#HustleAndSoul', 'Derry', '#WeirdDateStories', '#WeLoveTheEarth', 'Oshie', 'WE LOVE THE EARTH', '#FridayFeeling', '#DinahJane1', '"Earth"', 'Lil Dicky', 'Gallant', '#CriticalRoleSpoilers', 'Game 6', 'Yvie', 'Silky', '#MakeAMovieSensual', '#WhatStopsYouFromGoingHome', '#NRLBulldogsSouths', '#TheLegendOfVoxMachina', 'Kevin Durant', 'Seth Abramson', 'George Conway', '#fridaymotivation', '#GSWvsLAC', 'Lone Wolf and Cub'} 

11 common trends: {'#DragRace', 'Lyra McKee', '#DinahJane1', '#AFLNorthDons', '#BLACKPINKxCorden', '#ConCalmaRemix', 'Lil Dicky', 'Derrick White', '#NRLBulldogsSouths', 'Derry', '#WeLoveTheEarth'}
In [17]:
%%nose

# One or more tests of the students code. 
# The @solution should pass the tests.
# The purpose of the tests is to try to catch common errors and to 
# give the student a hint on how to resolve these errors.

def test_ww_trends():
    correct_world_trends = set([trend['name'] for trend in WW_trends[0]['trends']])
    assert world_trends == correct_world_trends, \
    'The variable world_trends does not have the expected trend names.'
   
def test_us_trends():
    correct_us_trends = set([trend['name'] for trend in US_trends[0]['trends']])
    assert us_trends == correct_us_trends, \
    'The variable us_trends does not have the expected trend names.'

def test_common_trends():
    correct_common_trends = world_trends.intersection(us_trends)
    assert common_trends == correct_common_trends, \
    'The variable common_trends does not have the expected common trend names.'
Out[17]:
3/3 tests passed

4. Exploring the hot trend

🕵️‍♀️ From the intersection (last output) we can see that, out of the two sets of trends (each of size 50), we have 11 overlapping topics. In particular, there is one common trend that sounds very interesting: #WeLoveTheEarth — so good to see that Twitteratis are unanimously talking about loving Mother Earth! 💚

Note: We could have had no overlap or a much higher overlap; when we did the query for getting the trends, people in the US could have been on fire obout topics only relevant to them.

Image Source:Official Music Video Cover: https://welovetheearth.org/video/

We have found a hot-trend, #WeLoveTheEarth. Now let's see what story it is screaming to tell us!
If we query Twitter's search API with this hashtag as query parameter, we get back actual tweets related to it. We have the response from the search API stored in the datasets folder as 'WeLoveTheEarth.json'. So let's load this dataset and do a deep dive in this trend.

In [4]:
# Loading the data
tweets = json.loads(open('datasets/WeLoveTheEarth.json').read())

# Inspecting some tweets
tweets[0:2]
Out[4]:
[{'created_at': 'Fri Apr 19 08:46:48 +0000 2019',
  'id': 1119160405270523904,
  'id_str': '1119160405270523904',
  'text': 'RT @lildickytweets: 🌎 out now #WeLoveTheEarth https://t.co/L22XsoT5P1',
  'truncated': False,
  'entities': {'hashtags': [{'text': 'WeLoveTheEarth', 'indices': [30, 45]}],
   'symbols': [],
   'user_mentions': [{'screen_name': 'lildickytweets',
     'name': 'LD',
     'id': 1209516660,
     'id_str': '1209516660',
     'indices': [3, 18]}],
   'urls': [{'url': 'https://t.co/L22XsoT5P1',
     'expanded_url': 'https://youtu.be/pvuN_WvF1to',
     'display_url': 'youtu.be/pvuN_WvF1to',
     'indices': [46, 69]}]},
  'metadata': {'iso_language_code': 'en', 'result_type': 'recent'},
  'source': '<a href="http://twitter.com/download/android" rel="nofollow">Twitter for Android</a>',
  'in_reply_to_status_id': None,
  'in_reply_to_status_id_str': None,
  'in_reply_to_user_id': None,
  'in_reply_to_user_id_str': None,
  'in_reply_to_screen_name': None,
  'user': {'id': 212375312,
   'id_str': '212375312',
   'name': 'fake smile',
   'screen_name': 'Pati95Poland',
   'location': 'SWAGLAND   ',
   'description': "''you just got knocked the fuck out''",
   'url': 'https://t.co/nxzlSyYZSK',
   'entities': {'url': {'urls': [{'url': 'https://t.co/nxzlSyYZSK',
       'expanded_url': 'http://loveeeujdb.tumblr.com/',
       'display_url': 'loveeeujdb.tumblr.com',
       'indices': [0, 23]}]},
    'description': {'urls': []}},
   'protected': False,
   'followers_count': 2306,
   'friends_count': 697,
   'listed_count': 28,
   'created_at': 'Fri Nov 05 22:25:29 +0000 2010',
   'favourites_count': 5552,
   'utc_offset': None,
   'time_zone': None,
   'geo_enabled': True,
   'verified': False,
   'statuses_count': 185750,
   'lang': 'pl',
   'contributors_enabled': False,
   'is_translator': False,
   'is_translation_enabled': False,
   'profile_background_color': 'FFFFFF',
   'profile_background_image_url': 'http://abs.twimg.com/images/themes/theme18/bg.gif',
   'profile_background_image_url_https': 'https://abs.twimg.com/images/themes/theme18/bg.gif',
   'profile_background_tile': False,
   'profile_image_url': 'http://pbs.twimg.com/profile_images/1093929135183937537/hQuxtwKq_normal.jpg',
   'profile_image_url_https': 'https://pbs.twimg.com/profile_images/1093929135183937537/hQuxtwKq_normal.jpg',
   'profile_banner_url': 'https://pbs.twimg.com/profile_banners/212375312/1522705183',
   'profile_link_color': 'ABB8C2',
   'profile_sidebar_border_color': 'FFFFFF',
   'profile_sidebar_fill_color': 'F6F6F6',
   'profile_text_color': '333333',
   'profile_use_background_image': True,
   'has_extended_profile': True,
   'default_profile': False,
   'default_profile_image': False,
   'following': False,
   'follow_request_sent': False,
   'notifications': False,
   'translator_type': 'regular'},
  'geo': None,
  'coordinates': None,
  'place': None,
  'contributors': None,
  'retweeted_status': {'created_at': 'Fri Apr 19 04:22:29 +0000 2019',
   'id': 1119093888524754946,
   'id_str': '1119093888524754946',
   'text': '🌎 out now #WeLoveTheEarth https://t.co/L22XsoT5P1',
   'truncated': False,
   'entities': {'hashtags': [{'text': 'WeLoveTheEarth', 'indices': [10, 25]}],
    'symbols': [],
    'user_mentions': [],
    'urls': [{'url': 'https://t.co/L22XsoT5P1',
      'expanded_url': 'https://youtu.be/pvuN_WvF1to',
      'display_url': 'youtu.be/pvuN_WvF1to',
      'indices': [26, 49]}]},
   'metadata': {'iso_language_code': 'en', 'result_type': 'recent'},
   'source': '<a href="http://twitter.com" rel="nofollow">Twitter Web Client</a>',
   'in_reply_to_status_id': None,
   'in_reply_to_status_id_str': None,
   'in_reply_to_user_id': None,
   'in_reply_to_user_id_str': None,
   'in_reply_to_screen_name': None,
   'user': {'id': 1209516660,
    'id_str': '1209516660',
    'name': 'LD',
    'screen_name': 'lildickytweets',
    'location': 'Earth',
    'description': 'Rapper/Actor/Comedian/Model #WeLoveTheEarth',
    'url': 'https://t.co/aFrPkkJKqs',
    'entities': {'url': {'urls': [{'url': 'https://t.co/aFrPkkJKqs',
        'expanded_url': 'https://LilDicky.lnk.to/Earth',
        'display_url': 'LilDicky.lnk.to/Earth',
        'indices': [0, 23]}]},
     'description': {'urls': []}},
    'protected': False,
    'followers_count': 503111,
    'friends_count': 945,
    'listed_count': 657,
    'created_at': 'Fri Feb 22 19:06:15 +0000 2013',
    'favourites_count': 7696,
    'utc_offset': None,
    'time_zone': None,
    'geo_enabled': False,
    'verified': True,
    'statuses_count': 14430,
    'lang': 'en',
    'contributors_enabled': False,
    'is_translator': False,
    'is_translation_enabled': False,
    'profile_background_color': '000000',
    'profile_background_image_url': 'http://abs.twimg.com/images/themes/theme14/bg.gif',
    'profile_background_image_url_https': 'https://abs.twimg.com/images/themes/theme14/bg.gif',
    'profile_background_tile': False,
    'profile_image_url': 'http://pbs.twimg.com/profile_images/1119087366679846912/XSa4fpQA_normal.png',
    'profile_image_url_https': 'https://pbs.twimg.com/profile_images/1119087366679846912/XSa4fpQA_normal.png',
    'profile_banner_url': 'https://pbs.twimg.com/profile_banners/1209516660/1555646206',
    'profile_link_color': '858585',
    'profile_sidebar_border_color': 'FFFFFF',
    'profile_sidebar_fill_color': 'DDEEF6',
    'profile_text_color': '333333',
    'profile_use_background_image': True,
    'has_extended_profile': False,
    'default_profile': False,
    'default_profile_image': False,
    'following': False,
    'follow_request_sent': False,
    'notifications': False,
    'translator_type': 'none'},
   'geo': None,
   'coordinates': None,
   'place': None,
   'contributors': None,
   'is_quote_status': False,
   'retweet_count': 7482,
   'favorite_count': 13317,
   'favorited': False,
   'retweeted': False,
   'possibly_sensitive': False,
   'lang': 'en'},
  'is_quote_status': False,
  'retweet_count': 7482,
  'favorite_count': 0,
  'favorited': False,
  'retweeted': False,
  'possibly_sensitive': False,
  'lang': 'en'},
 {'created_at': 'Fri Apr 19 08:46:48 +0000 2019',
  'id': 1119160404876206080,
  'id_str': '1119160404876206080',
  'text': '💚🌎💚  #WeLoveTheEarth 👇🏼',
  'truncated': False,
  'entities': {'hashtags': [{'text': 'WeLoveTheEarth', 'indices': [5, 20]}],
   'symbols': [],
   'user_mentions': [],
   'urls': []},
  'metadata': {'iso_language_code': 'und', 'result_type': 'recent'},
  'source': '<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a>',
  'in_reply_to_status_id': None,
  'in_reply_to_status_id_str': None,
  'in_reply_to_user_id': None,
  'in_reply_to_user_id_str': None,
  'in_reply_to_screen_name': None,
  'user': {'id': 72150460,
   'id_str': '72150460',
   'name': 'Alfonsina del Mar (Dianishka Prietishka)',
   'screen_name': 'Diana____X',
   'location': 'México',
   'description': '☸︎ ⚓︎ 👩🏻\u200d✈️ ★★★★ ♒︎',
   'url': None,
   'entities': {'description': {'urls': []}},
   'protected': False,
   'followers_count': 223,
   'friends_count': 513,
   'listed_count': 0,
   'created_at': 'Sun Sep 06 23:26:24 +0000 2009',
   'favourites_count': 750,
   'utc_offset': None,
   'time_zone': None,
   'geo_enabled': True,
   'verified': False,
   'statuses_count': 1668,
   'lang': 'es',
   'contributors_enabled': False,
   'is_translator': False,
   'is_translation_enabled': False,
   'profile_background_color': '642D8B',
   'profile_background_image_url': 'http://abs.twimg.com/images/themes/theme10/bg.gif',
   'profile_background_image_url_https': 'https://abs.twimg.com/images/themes/theme10/bg.gif',
   'profile_background_tile': True,
   'profile_image_url': 'http://pbs.twimg.com/profile_images/1072296818531278848/tgn0e2h4_normal.jpg',
   'profile_image_url_https': 'https://pbs.twimg.com/profile_images/1072296818531278848/tgn0e2h4_normal.jpg',
   'profile_banner_url': 'https://pbs.twimg.com/profile_banners/72150460/1545198367',
   'profile_link_color': '8400FF',
   'profile_sidebar_border_color': '65B0DA',
   'profile_sidebar_fill_color': '7AC3EE',
   'profile_text_color': '3D1957',
   'profile_use_background_image': True,
   'has_extended_profile': True,
   'default_profile': False,
   'default_profile_image': False,
   'following': False,
   'follow_request_sent': False,
   'notifications': False,
   'translator_type': 'none'},
  'geo': None,
  'coordinates': None,
  'place': None,
  'contributors': None,
  'is_quote_status': False,
  'retweet_count': 0,
  'favorite_count': 0,
  'favorited': False,
  'retweeted': False,
  'lang': 'und'}]
In [19]:
%%nose
# %%nose needs to be included at the beginning of every @tests cell

# One or more tests of the student's code
# The @solution should pass the tests
# The purpose of the tests is to try to catch common errors and
# to give the student a hint on how to resolve these errors

def test_tweets_loaded_correctly():
    correct_tweets_data = json.loads(open('datasets/WeLoveTheEarth.json').read())
    assert correct_tweets_data == tweets, "The variable tweets should contain the data in WeLoveTheEarth.json."
    
Out[19]:
1/1 tests passed

5. Digging deeper

🕵️‍♀️ Printing the first two tweet items makes us realize that there’s a lot more to a tweet than what we normally think of as a tweet — there is a lot more than just a short text!


But hey, let's not get overwhemled by all the information in a tweet object! Let's focus on a few interesting fields and see if we can find any hidden insights there.

In [5]:
# Extracting the text of all the tweets from the tweet object
texts = [tweet['text'] 
                 for tweet in tweets ]

# Extracting screen names of users tweeting about #WeLoveTheEarth
names = [user_mention['screen_name'] 
                 for tweet in tweets
                     for user_mention in tweet['entities']['user_mentions']]

# Extracting all the hashtags being used when talking about this topic
hashtags = [hashtag['text'] 
             for tweet in tweets
                 for hashtag in tweet['entities']['hashtags']]

# Inspecting the first 10 results
print (json.dumps(texts[0:10], indent=1),"\n")
print (json.dumps(names[0:10], indent=1),"\n")
print (json.dumps(hashtags[0:10], indent=1),"\n")
[
 "RT @lildickytweets: \ud83c\udf0e out now #WeLoveTheEarth https://t.co/L22XsoT5P1",
 "\ud83d\udc9a\ud83c\udf0e\ud83d\udc9a  #WeLoveTheEarth \ud83d\udc47\ud83c\udffc",
 "RT @cabeyoomoon: Ta piosenka to bop,  wpada w ucho  i dochody z niej id\u0105 na dobry cel,  warto s\u0142ucha\u0107 w k\u00f3\u0142ko i w k\u00f3\u0142ko gdziekolwiek si\u0119 ty\u2026",
 "#WeLoveTheEarth \nCzemu ja si\u0119 pop\u0142aka\u0142am",
 "RT @Spotify: This is epic. @lildickytweets got @justinbieber, @arianagrande, @halsey, @sanbenito, @edsheeran, @SnoopDogg, @ShawnMendes, @Kr\u2026",
 "RT @biebercentineo: Justin : are we gonna die? \nLil dicky: you know bieber we might die \n\nBTCH IM CRYING #EARTH #WeLoveTheEarth #WELOVEEART\u2026",
 "RT @dreamsiinflate: #WeLoveTheEarth \u201ci am a fat fucking pig\u201d okay brendon urie https://t.co/FdJmq31xZc",
 "Literally no one:\n\nMe in the past 4 hours:\n\nI'm a koala and I sleep all the time, so what, it's cute \ud83c\udfb6\n\n#WeLoveTheEarth #EdSheeranTheKoala",
 "RT @Yuuupthatsme: Mia\u0142e\u015b by\u0107 \u017cyraf\u0105 #WeLoveTheEarth https://t.co/0kNCpU8o6q",
 "RT @jaguareffects: eu prestando aten\u00e7\u00e3o no \u00e1udio pra identificar cada artista\n\n#WeLoveTheEarth https://t.co/0cDtiV2t1E"
] 

[
 "lildickytweets",
 "cabeyoomoon",
 "Spotify",
 "lildickytweets",
 "justinbieber",
 "ArianaGrande",
 "halsey",
 "sanbenito",
 "edsheeran",
 "SnoopDogg"
] 

[
 "WeLoveTheEarth",
 "WeLoveTheEarth",
 "WeLoveTheEarth",
 "EARTH",
 "WeLoveTheEarth",
 "WeLoveTheEarth",
 "WeLoveTheEarth",
 "EdSheeranTheKoala",
 "WeLoveTheEarth",
 "WeLoveTheEarth"
] 

In [21]:
%%nose
# %%nose needs to be included at the beginning of every @tests cell

# One or more tests of the student's code
# The @solution should pass the tests
# The purpose of the tests is to try to catch common errors and
# to give the student a hint on how to resolve these errors

def test_extracted_texts():
    correct_text = [tweet['text'] for tweet in tweets ]
    assert texts == correct_text, \
    'The variable texts does not have the expected text data.'
   
def test_extracted_names():
    correct_names = [user_mention['screen_name'] 
                         for tweet in tweets 
                             for user_mention in tweet['entities']['user_mentions']]
    assert correct_names == names, \
    'The variable names does not have the expected user names.'
    
def test_extracted_hashtags():
    correct_hashtags = [hashtag['text'] 
                            for tweet in tweets
                                 for hashtag in tweet['entities']['hashtags']]
    assert correct_hashtags == hashtags, \
    'The variable hashtags does not have the expected hashtag data.'
Out[21]:
3/3 tests passed

6. Frequency analysis

🕵️‍♀️ Just from the first few results of the last extraction, we can deduce that:

  • We are talking about a song about loving the Earth.
  • A lot of big artists are the forces behind this Twitter wave, especially Lil Dicky.
  • Ed Sheeran was some cute koala in the song — "EdSheeranTheKoala" hashtag! 🐨

Observing the first 10 items of the interesting fields gave us a sense of the data. We can now take a closer look by doing a simple, but very useful, exercise — computing frequency distributions. Starting simple with frequencies is generally a good approach; it helps in getting ideas about how to proceed further.

In [6]:
# Importing modules
from collections import Counter

# Counting occcurrences/ getting frequency dist of all names and hashtags
for item in [names, hashtags]:
    c = Counter(item)    
    # Inspecting the 10 most common items in c
    print (c.most_common(10), "\n")
[('lildickytweets', 102), ('LeoDiCaprio', 44), ('ShawnMendes', 33), ('halsey', 31), ('ArianaGrande', 30), ('justinbieber', 29), ('Spotify', 26), ('edsheeran', 26), ('sanbenito', 25), ('SnoopDogg', 25)] 

[('WeLoveTheEarth', 313), ('4future', 12), ('19aprile', 12), ('EARTH', 11), ('fridaysforfuture', 10), ('EarthMusicVideo', 3), ('ConCalmaRemix', 3), ('Earth', 3), ('aliens', 2), ('AvengersEndgame', 2)] 

In [23]:
%%nose
# %%nose needs to be included at the beginning of every @tests cell

# One or more tests of the student's code
# The @solution should pass the tests
# The purpose of the tests is to try to catch common errors and
# to give the student a hint on how to resolve these errors

def test_counter():
    for item in [names, hashtags]: correct_counter = Counter(item)  
    assert c == correct_counter, \
    "The variable c does not have the expected values."
Out[23]:
1/1 tests passed

7. Activity around the trend

🕵️‍♀️ Based on the last frequency distributions we can further build-up on our deductions:

  • We can more safely say that this was a music video about Earth (hashtag 'EarthMusicVideo') by Lil Dicky.
  • DiCaprio is not a music artist, but he was involved as well (Leo is an environmentalist so not a surprise to see his name pop up here).
  • We can also say that the video was released on a Friday; very likely on April 19th.

We have been able to extract so many insights. Quite powerful, isn't it?!


Let's further analyze the data to find patterns in the activity around the tweets — did all retweets occur around a particular tweet?

If a tweet has been retweeted, the 'retweeted_status' field gives many interesting details about the original tweet itself and its author.

We can measure a tweet's popularity by analyzing the retweetcount and favoritecount fields. But let's also extract the number of followers of the tweeter — we have a lot of celebs in the picture, so can we tell if their advocating for #WeLoveTheEarth influenced a significant proportion of their followers?


Note: The retweet_count gives us the total number of times the original tweet was retweeted. It should be the same in both the original tweet and all the next retweets. Tinkering around with some sample tweets and the official documentaiton are the way to get your head around the mnay fields.

In [7]:
# Extracting useful information from retweets
retweets = [
             (tweet['retweet_count'], 
              tweet['retweeted_status']['favorite_count'],
              tweet['retweeted_status']['user']['followers_count'],
              tweet['retweeted_status']['user']['screen_name'],
              tweet['text']) 
            
            for tweet in tweets 
                if 'retweeted_status' in tweet
           ]
In [25]:
%%nose
# %%nose needs to be included at the beginning of every @tests cell

# One or more tests of the student's code
# The @solution should pass the tests
# The purpose of the tests is to try to catch common errors and
# to give the student a hint on how to resolve these errors

def test_retweets():
    correct_retweets = [
             (tweet['retweet_count'], 
              tweet['retweeted_status']['favorite_count'],
              tweet['retweeted_status']['user']['followers_count'],
              tweet['retweeted_status']['user']['screen_name'],
              tweet['text']) 
            
            for tweet in tweets 
                if 'retweeted_status' in tweet
           ]
    assert correct_retweets == retweets, \
    "The retweets variable does not have the expected values. Check the names of the extracted field and their order."
Out[25]:
1/1 tests passed

8. A table that speaks a 1000 words

Let's manipulate the data further and visualize it in a better and richer way — "looks matter!"

In [8]:
# Importing modules
import matplotlib.pyplot as plt
import pandas as pd

# Visualizing the data in a pretty and insightful format
df = pd.DataFrame(
    retweets, 
    columns=['Retweets','Favorites','Followers','ScreenName','Text']).groupby(
    ['ScreenName','Text','Followers']).sum().sort_values(by=['Followers'], ascending=False)

df.style.background_gradient()
Out[8]:
Retweets Favorites
ScreenName Text Followers
katyperry RT @katyperry: Sure, the Mueller report is out, but @lildickytweets’ "Earth" but will be too tonight. Don't say I never tried to save the w… 107195569 2338 10557
107195568 2338 10556
TheEllenShow RT @TheEllenShow: .@lildickytweets, @justinbieber, @MileyCyrus, @katyperry, @ArianaGrande and more, all in one music video. My head might e… 77474826 2432 10086
LeoDiCaprio RT @LeoDiCaprio: The @dicapriofdn partners that will benefit from this collaboration include @SharkRayFund, @SolutionsProj, @GreengrantsFun… 18988898 28505 78137
RT @LeoDiCaprio: Thank you to @lildickytweets and all the artists that came together to make this happen. Net profits from the song, video,… 18988898 149992 416018
halsey RT @halsey: 🐯🐯🐯 meeeeeeeow 👅 #WeLoveTheEarth https://t.co/JJr6vmKG7U 10564842 7742 69684
10564841 7742 69682
scooterbraun RT @scooterbraun: Watch #EARTH NOW! #WeLoveTheEarth — https://t.co/OtRfIgcSZL 3885179 5925 14635
Spotify RT @Spotify: This is epic. @lildickytweets got @justinbieber, @arianagrande, @halsey, @sanbenito, @edsheeran, @SnoopDogg, @ShawnMendes, @Kr… 2973277 107222 237259
TomHall RT @TomHall: 🐆 Look Out! 🐆 #Cheetah @LeoDiCaprio #FridayFeeling #WeLoveTheEarth https://t.co/w1O1NyTbwX 590841 82 252
lildickytweets RT @lildickytweets: Earth. 4/18 at 9PM PST. #WeLoveTheEarth pre-save link in my bio https://t.co/7HD2xlSFYQ 503112 25098 90974
RT @lildickytweets: 🌎 out now #WeLoveTheEarth https://t.co/L22XsoT5P1 503112 112230 199773
503111 119712 213072
greenpeacefr RT @greenpeacefr: Happening NOW in France : today, to show how much #WeLoveTheEarth, more than 2000 citizens are blocking the headquarters… 420789 128 192
rlthingy RT @rlthingy: /rlt/ YO GUYS LISTEN TO THIS SONGGGGG #WeLoveTheEarth https://t.co/trUgRG7QBH 225977 11 23
SB_Projects RT @SB_Projects: #WeLoveTheEarth out now with @lildickytweets, @justinbieber, @ArianaGrande, @zacbrownband, and 25+ of your other faves htt… 98418 271 730
biebernovidade RT @biebernovidade: Rio de Janeiro: PRESENTE! #WeLoveTheEarth https://t.co/IJrypKqzSf 83281 651 1499
MendesCrewInfo RT @MendesCrewInfo: .@ShawnMendes represents rhinos in the ‘Earth’ music video and feature. His line, “We’re just some rhinos, horny as hec… 61015 2815 9599
shawnxniallx RT @shawnxniallx: La gente piensa que el calentamiento global no es real, ya abran los ojos y actuemos de una manera real, dime ¿qué te cue… 53713 812 1254
RT @shawnxniallx: La humanidad es un asco y nunca me cansaré de decirlos ¿no creen que es momento de cambiar? Salvemos nuestro planeta, sal… 53713 604 1034
RT @shawnxniallx: Vengo a recomendarles a todos esta miniserie que realizó Netflix, en la cual nos muestra cada parte de las especies, lo q… 53713 138 299
RT @shawnxniallx: Espero que con este video se pueda crear un poco más de conciencia propia, simeplemnte estamos acabando con nuestro plane… 53713 300 494
SMendesQandA RT @SMendesQandA: #WeLoveTheEarth https://t.co/KDIKYVHFWU 53282 56 339
RT @SMendesQandA: Let’s help save the Earth. We’re the ones with the power of change. 🌍 #WeLoveTheEarth 53282 122 343
RT @SMendesQandA: So you can basically say you have a song with many of the artists we have asked you to collaborate with...smart move mend… 53282 116 717
RT @SMendesQandA: “We’re just some rhinos, horny as heck” — Shawn’s part on #WeLoveTheEarth 53282 244 1420
RT @SMendesQandA: “We’re just some rhinos horny as heck” — Shawn Mendes #WeLoveTheEarth https://t.co/URnHb0DTWN 53282 768 3309
ShawnUpdatesSA RT @ShawnUpdatesSA: Shawn Mendes: rinocerontes. #WeLoveTheEarth 'La población de rinocerontes negros está casi extinta, y las otras cuatro… 52424 850 1807
gtbriel RT @gtbriel: vimos o cu do justin bieber logo em seguida a ariana sair do cu do justin e logo em seguuda a ariana sendo morta pela halse… 49215 581 970
MileySmilerNews RT @MileySmilerNews: Miley’s cameo in the Earth song is so cute #WeLoveTheEarth https://t.co/Byk9rkhMpG 47840 15 116
ArianatorFallen RT @ArianatorFallen: Ariana vocals had saved the earth . This song is so important #WeLoveTheEarth https://t.co/Lg9jsPRD5z 44426 84 258
MendesNotified RT @MendesNotified: Rhinos - Shawn Mendes🦏🖤 “The black rhino population is nearly extinct, and the four other species of rhinos found in Af… 39726 258 858
RT @MendesNotified: shawn reading his line for the song #WeLoveTheEarth: https://t.co/dcWJFDlVMd 39726 2465 10475
badweputation RT @badweputation: n adianta vcs comentarem sobre a importância da preservação hj e amanhã já esquecerem e tbm lembrando q o atual presiden… 38787 119 183
isbreakls RT @isbreakls: Queria dizer que na música do Lil Dicky tem 28 artistas incríveis mais quem eu amo mesmo é um babuíno chamado Justin Bieber.… 37473 95 215
RT @isbreakls: A música e o clipe tá incrível vamos espalhar o verdadeiro motivo da música que é fazer com que as pessoas pensem nos seus a… 37473 684 1068
NoticiasSmilers RT @NoticiasSmilers: Soy un elefante, tengo basura en mi trompa. -Pequeño cameo de Miley en la canción Earth de Lil Dicky- #WeLoveTheEarth… 32649 7 4
ThrowbacksBTS RT @ThrowbacksBTS: Friendly reminder to use less plastic, recycle and contribute in some way to benefit humanity. The world is dying we nee… 32498 370 816
btsargento RT @btsargento: ▪ estas son varias cosas que podemos hacer para construir un planeta mejor, sin contaminación y un lugar donde todos aporte… 31453 67 143
biebersmaniabrs RT @biebersmaniabrs: SAIU! Ouçam e assistam “Earth”, música de Lil Dicky com Justin Bieber e mais 29 artistas. 🌏🎶 Video: https://t.co/oHRR… 26097 341 463
landsrauhl RT @landsrauhl: I loved what lil dicky did. There’s so many popular artists on the track which hopefully means more of a variety of people… 25071 128 306
biebsrell RT @biebsrell: J: ¿Vamos a morir? L: ¿Sabes qué, Bieber? Podríamos morir. No voy a mentirte. Quiero decir, hay mucha gente ahí afuera que n… 23301 730 1344
ShawnNewsPoland RT @ShawnNewsPoland: “We’re just some rhinos, horny as heck” — Shawna tekst w piosence #WeLoveTheEarth https://t.co/NsOmYfoe7u 22067 97 523
RT @ShawnNewsPoland: Wyjaśnienie tekstu Shawna #WeLoveTheEarth https://t.co/NiShcC8WGW 22067 105 440
RT @ShawnNewsPoland: Słuchajcie wszędzie gdzie się da! #WeLoveTheEarth dochód z piosenki zostanie przekazany fundacji założonej przez DiCap… 22067 4410 8720
NLiddle16 RT @NLiddle16: #Earth isn’t supposed to break records or chart. This song is to bring awareness. We have to change now. We have to love mor… 21180 27 134
ArianaRenewsFR RT @ArianaRenewsFR: #WeLoveTheEarth est maintenant disponible sur toutes les plateformes ! YouTube : https://t.co/zSpCdE74lV iTunes : ht… 20794 5 20
iBeliebersMx RT @iBeliebersMx: Justin: ¿Vamos a morir? Lil Dicky: "Sabes Bieber... podemos morir. No te voy a mentir a ti, hay muchas personas que pien… 19745 2236 3872
JBCrewdotcom RT @JBCrewdotcom: #WeLoveTheEarth Merchandise available to purchase with proceeds going to The Leonardo DiCaprio Foundation dedicated to th… 17812 89 186
dimplecabello RT @dimplecabello: “¿Que vamos a defender? El amor. Y nosotros amamos la tierra.” Este video es precioso, últimamente estamos dañando tanto… 17590 286 445
TeamAGPoland RT @TeamAGPoland: Utwór "Earth" jest już dostępny! Ariana wcieliła się w postać zebry, a cały dochód ze sprzedaży utworu zostanie przekazan… 17157 44 142
bieberpakiss RT @bieberpakiss: HI IM A BABOON IM LIKE A MAN JUST LESS ADVANCED AND MY ANUS IS HUGE #WeLoveTheEarth https://t.co/tqhfvv7PKf 16288 148 286
yourbiebernews RT @yourbiebernews: Justin Bieber: Baboon #WeLoveTheEarth https://t.co/dlvl1M28Mg 14121 198 404
bizzleslovej RT @bizzleslovej: Parliamo di Leo DiCaprio che entra in scena sulla nave del Titanic stile Jack #WeLoveTheEarth https://t.co/VxZscAiOhZ 13151 5 8
holdtightlive RT @holdtightlive: THIS SONG IS SO BEAUTIFUL THE VIDEO IS ABSOLUTELY AMAZING AND IT’S FOR A GOOD CAUSE SO LETS GOOO STREAM IT BUY IT WATCH… 10331 35 83
needyellie RT @needyellie: please keep steaming this song, all proceeds go to an extremely important cause. save planet earth!! #WeLoveTheEarth https:… 10319 1240 2884
gladwithmyidols RT @gladwithmyidols: So... Halsey killed Ariana #WeLoveTheEarth https://t.co/Qquu4YfgzE 9987 23 91
TJOfficial_ RT @TJOfficial_: We love the earth it is our planet 🌍 🎶 #WeLoveTheEarth It’s so beautiful. 9693 6 12
MCyrus__forever RT @MCyrus__forever: Cały dochód z tej piosenki trafi do fundacji Leonardo DiCaprio, poświęconej ochronie i dobrobytowi wszystkich mieszkań… 9680 46 79
RT @MCyrus__forever: Ten teledysk jest świetny, a piosenka ma naprawdę bardzo ważne przesłanie 🌎🌱 #WeLoveTheEarth 9680 1 5
justinxrespect RT @justinxrespect: “are we gonna die” ay loco. #WeLoveTheEarth https://t.co/zwof29P4Uw 9257 9 21
cyruseyes_ RT @cyruseyes_: Qui non stiamo parlando abbastanza di Leonardo DiCaprio e di questa scena #WeLoveTheEarth https://t.co/zUfOWBy7ct 9148 22 148
RT @cyruseyes_: Questo video deve diventare un film. Il messaggio arriverebbe veramente a tutti. @ Disney sai cosa fare #WeLoveTheEarth ht… 9148 10 52
ChartBTS RT @ChartBTS: "We love the earth it is our planet We love the earth it is our home" ARMYs, support this important cause, it is our home… 8527 705 1731
MileyDimension RT @MileyDimension: I think everyone should see this! It is about time to do something. #WeLoveTheEarth https://t.co/WmMDhsBq19 7745 645 969
cabeyoomoon RT @cabeyoomoon: Ta piosenka to bop, wpada w ucho i dochody z niej idą na dobry cel, warto słuchać w kółko i w kółko gdziekolwiek się ty… 7732 9 23
stonyproud RT @stonyproud: agora que percebi que o clipe todo foi no cu do Justin pqp que cu arrombado #WeLoveTheEarth https://t.co/I2edu6J9be 7728 49 115
hoe4exhoee RT @hoe4exhoee: Lil Dicky - Earth (Official Music Video) https://t.co/XT4xdm9XoN KRIS WU's PART IS ON 5:43. It is short but I'm so glad… 6870 10 8
KCUnidosBR RT @KCUnidosBR: Quem diria em KatyCats? 2 músicas no mesmo dia #ConCalmaRemix #WeLoveTheEarth https://t.co/FF7Be15lhz 6458 59 96
Ari_grandeJP RT @Ari_grandeJP: . @lildickytweets の 新曲 #EARTH が公開されました💙🌏 アリアナはシマウマとして参加してます!👀💗✨ #WeLoveTheEarth https://t.co/5g1clvAZoO 6141 44 306
becauseihadyou RT @becauseihadyou: Don’t know why people are being nasty about ‘Earth’. It’s not a song meant to chart or break records, it’s to raise awa… 5647 2484 6444
biebersmybro RT @biebersmybro: beliebers are promoting the song the hardest lol wbk we are the best fandom ever #WeLoveTheEarth 5314 14 49
RT @biebersmybro: WE FINALLY HEARD JUSTIN AND ARIANA IN ONE SONG #WeLoveTheEarth https://t.co/RqHTRButmx 5314 350 996
imagiwation RT @imagiwation: entre tanta coisa ruim e tóxica que tá tendo ultimamente a gente tem a chance de se unir por uma causa boa, então não vamo… 5208 88 129
triedsadlonel RT @triedsadlonel: piosenka mega mi sie podoba,taka fajna wesoła(pod katem melodii) natomiast calosc mnie hitnela mocno,bo to serio jest pr… 4941 10 34
RT @triedsadlonel: kiedy kazdy byl przekonany ze Shawn bedzie żyrafa a tu jeb nosorożcem #WeLoveTheEarth 4941 1 10
neznayuchtotut RT @neznayuchtotut: вау, так много артистов объединились, чтобы поднять насущную проблему нашей планеты о том, что ее нужно защищать и люби… 4621 8 150
demisfakesmile RT @demisfakesmile: stream. stream. stream this song. its for a good cause, let’s save the earth 🌍 💙💚 #WeLoveTheEarth https://t.co/vgABUfce… 4421 504 984
SoundOfSeries RT @SoundOfSeries: #INFOSOS : 'WeLoveTheEarth' est disponible sur YouTube. Le but de cette chanson n’est pas de devenir le tube de l’été,… 4393 80 72
carawcciolo RT @carawcciolo: Halsey zjada Ariane na śniadanie (koloryzowane) 😅 #WeLoveTheEarth https://t.co/FV4MZSOXlu 4246 63 194
gcldendays RT @gcldendays: Be careful who you call ugly in middle school 😉 #WeLoveTheEarth https://t.co/4jvr8Xn397 4122 394 1698
RT @gcldendays: No one: Not even a soul: Me: #WeLoveTheEarth https://t.co/i4BxsXBwny 4122 408 1189
biebercentineo RT @biebercentineo: Justin : are we gonna die? Lil dicky: you know bieber we might die BTCH IM CRYING #EARTH #WeLoveTheEarth #WELOVEEART… 4038 1551 3555
RT @biebercentineo: THIS SONG IS SO GOOD 😭 #EARTH #WeLoveTheEarth https://t.co/3hM7ZU2eYh 4038 79 215
Bizzbiebsz RT @Bizzbiebsz: So after so many years we finally got Justin x Arina collab and they even gave us zebra and baboon Stream #WeloveTheEarth… 3889 297 879
jvkejams RT @jvkejams: I feel like the song will showcase the animals in a very comedic way (bc its how most lil dicky’s songs are) to raise awarene… 3861 20 104
larryxcolours RT @larryxcolours: ¿Cómo pueden ayudar a la organización? -Compren la mercancia, las ganancias irán directamente para ayudar a la tierra.… 3766 330 612
sitevolts RT @sitevolts: CROSSOVER MAIOR QUE VINGADORES 😵 Justin Bieber, Ariana Grande, Katy Perry, Halsey, Sia, Ed Sheeran, Meghan Trainor e Miley C… 3707 130 366
JDBieberPol RT @JDBieberPol: Gwiazdy jako zwierzęta w teledysku #Earth #WeLoveTheEarth https://t.co/3aA4mE56Y3 3475 34 99
nervous_taste RT @nervous_taste: Have u thought that we will have: SHAWN MENDES FT ARIANA GRANDE SHAWN MENDES FT JUSTIN BIEBER SHAWN MENDES FT HALSEY… 3283 2 9
RT @nervous_taste: Shawn isn’t the giraffe #WeLoveTheEarth https://t.co/0PJdZnkP87 3283 2 0
nopromisesv RT @nopromisesv: A ogólnie sam teledysk jest świetny, nie spodziewałam się tego #WeLoveTheEarth 3283 7 77
INLOVEWITHDS RT @INLOVEWITHDS: Questo video è semplicemente spettacolare e il messaggio che vuole trasmettere è bellissimo wow non ho parole Tutti gli a… 3153 14 49
agbkissy RT @agbkissy: all of yall saying earth is a bad song are immature... its not supposed to be the next big hit, it was made to spread awarene… 3098 584 1356
dreamsiinflate RT @dreamsiinflate: #WeLoveTheEarth “i am a fat fucking pig” okay brendon urie https://t.co/FdJmq31xZc 3045 1107 3426
RT @dreamsiinflate: #WeLoveTheEarth they are all these informative cards on the website which are pretty cool https://t.co/qq0GWJ0q0G 3045 208 840
SMendesMedia RT @SMendesMedia: . @ShawnMendes’ part on l “Earth” 🌎 #WeLoveTheEarth (@lildickytweets) • https://t.co/XrpJbZ6zY7 https://t.co/o2dO7V5cz4 2815 238 1120
kyzztin RT @kyzztin: The whole concept of this is super dope. lil dicky really got so many huge artists to be part of this amazing project and give… 2641 21 79
RT @kyzztin: same energy #WeloveTheEarth https://t.co/YfTTS6BRiC 2641 10 27
xKittyMendes RT @xKittyMendes: SHAWN JEST NOSOROŻCEM Jego od razu poznałam, bo z innymi miałam problem XD #WeLoveTheEarth https://t.co/21ICMTDdmn 2597 48 426
RT @xKittyMendes: Nie sądziłam, że potrzebuję usłyszeć z ust Shawna słowa horny XDD #WeLoveTheEarth https://t.co/TkMA07iNj5 2597 326 1074
kajagafelgaja RT @kajagafelgaja: macie tu moją przemowe #WeLoveTheEarth https://t.co/1KKrPIRllX 2526 1 0
RT @kajagafelgaja: czy to Was nie dociera że ta piosenka nie ma być dobra, tylko prosta, trafiająca do wszystkich i wpadająca w ucho? i moż… 2526 30 32
luvmyburito RT @luvmyburito: głosy ariany i justina tak do siebie pasują ze i'm in shook #WeLoveTheEarth https://t.co/MLmyex9t1t 2520 90 405
lordefurler RT @lordefurler: Sia did that! #WeLoveTheEarth https://t.co/aETvluquXM 2488 4 26
sinsnvices RT @sinsnvices: utożsamiam się z brendonem #WeLoveTheEarth https://t.co/bSLoyWD4hd 2478 1646 3466
kingoftheclout RT @kingoftheclout: STOP SCROLLING AND WATCH THIS VIDEO‼️ please take some time out of your day to watch this video & possibly share it. it… 2124 178 242
izrnsrdn RT @izrnsrdn: Justin Drew Bieber as a baboon #WeLoveTheEarth https://t.co/Wz8YK6r21q 2034 223 615
marquezduo RT @marquezduo: jakby ktoś się zastanawiał jak wygląda moje życie #WeLoveTheEarth https://t.co/SLvLE6eY0V 1906 582 1389
5SecOfMendess RT @5SecOfMendess: Ejjj ale mi się ta piosenka serio podoba i ma genialne przesłanie!💕 #WeLoveTheEarth 1870 8 35
JBwakeup RT @JBwakeup: Ogolnie to serio glos Justina i Ariany pasuja do siebie.. chce ich colab #WeLoveTheEarth 1842 14 58
MNotifiedMedia RT @MNotifiedMedia: Shawn Mendes the Rhino🦏 #WeLoveTheEarth https://t.co/Y2plDHsIsL 1805 93 416
RT @MNotifiedMedia: “we’re just some rhinos horny as heck” THE RHINOS ARE SO CUTE🦏 #WeLoveTheEarth https://t.co/vvkaO2U7qj 1805 175 647
DOLANVVY RT @DOLANVVY: Rozjebał mnie snoop dog jako marihuana, rola idealna dla niego #WeLoveTheEarth 1803 44 140
justinsbicep RT @justinsbicep: I signed the petition. And you should too. Stream, donate and spread the message. Let's save the earth. #WeLoveTheEarth h… 1772 58 101
purpxs3bizzle RT @purpxs3bizzle: "O homem destrói a natureza com desculpa de sobreviver, a natureza luta para sobreviver para garantir a sobrevivência do… 1716 144 224
kba_yankee21 RT @kba_yankee21: Never thought I would tear up because of a Lil Dicky song. But here I am crying in a cool way. Feel free to visit https:/… 1674 4 6
beth_powell1 RT @beth_powell1: LETS SAVE THE PLANET #WeLoveTheEarth 1629 1 0
piggzyneedy RT @piggzyneedy: i see so many people tweeting about saving the planet but i bet my whole life the majority of those people are only tweeti… 1577 1 2
particularangel RT @particularangel: i mean we should all listen to this part specifically #WeLoveTheEarth https://t.co/tgGZKRgXV2 1511 1147 2259
avisbelieberboy RT @avisbelieberboy: De lo mejor que va del año #WeLoveTheEarth https://t.co/vN7wPOGork 1367 3 4
biebrforro RT @biebrforro: justin y ariana cantando juntos es lo mejor que puede existir #WeLoveTheEarth https://t.co/Dilro999ds 1352 292 626
shawnnsbabyy RT @shawnnsbabyy: Il rinoceronte con la voce più bella del mondo🥰 #WeLoveTheEarth https://t.co/aSQgvumgKl 1314 2 6
br_atd RT @br_atd: O melhor porco gordo do universo !!! #WeLoveTheEarth https://t.co/lJfZkgnkWI 1249 1 1
moarjustln RT @moarjustln: can't believe we listened to justin's voice after months and I still in love #WeLoveTheEarth https://t.co/JhFRENhOH3 1216 58 158
AGPLOfficial RT @AGPLOfficial: Nawet gdy jest zebrą, Ariana zawsze serwuje wokal! 🎶 #WeLoveTheEarth Posłuchaj utworu “Earth” z Arianą Grande i plejadą… 1152 52 166
xmendesly RT @xmendesly: stream earth by lil dicky #WeLoveTheEarth 1129 1 0
sourdieselzain RT @sourdieselzain: “I’m a fat fucking pig” no ja się tu poplacze zaraz #WeLoveTheEarth #EarthMusicVideo https://t.co/tpBQZeRQEh 1048 34 99
MrtummyV RT @MrtummyV: This is so cute!! aslskfjdkskskkskak #WeLoveTheEarth https://t.co/ZKKKNFQ1Wf 1005 10 45
ringsofmendes RT @ringsofmendes: głos ari tutaj >>>>>>>>> #WeLoveTheEarth https://t.co/QDBVWZ0aom 1005 22 119
chimmybby RT @chimmybby: We Also Love The Sun 🌞 #WeLoveTheEarth https://t.co/mh9gfO6Z30 1004 34 129
PManice RT @PManice: “I’m a koala and I sleep all the time. So what? It’s cute.” 😍 #WeLoveTheEarth https://t.co/vyOvLY4bSE 979 33 107
awanasghena RT @awanasghena: KATY IN TENDENZA IN ITALIA. PIANGO😭🔥❤️ #ConCalmaRemix #WeLoveTheEarth https://t.co/CGnsmSd1gM 895 7 14
opssmymendes RT @opssmymendes: bardzo mi się podoba to, że można kupić merch i pieniądze z tego idą na ratowanie naszej planety #WeLoveTheEarth 849 1 2
RT @opssmymendes: warto sobie wejść na stronę https://t.co/JyL7e4jrbv i poczytać o co chodzi z każdym zwierzęciem #WeLoveTheEarth 849 84 112
_Sunfflower_ RT @_Sunfflower_: TA PIOSENKA TO ZŁOTO I DIAMENTY Oby jej przekaz nie skończył się tylko tylko na tym, że ludzie będą ją kojarzyli, bo spok… 784 164 480
jaguareffects RT @jaguareffects: eu prestando atenção no áudio pra identificar cada artista #WeLoveTheEarth https://t.co/0cDtiV2t1E 771 253 380
cerberusgrande RT @cerberusgrande: wszyscy mówią jak bardzo chcieliby usłyszeć biebera i ariane (same), ale ja bym chciała usłyszeć ariana x halsey, którą… 759 3 7
suplisamanobal RT @suplisamanobal: Not blackpink related but Lil dicky x justin bieber, ft ariana grande, and shawn mendes, also charlie puth, and sia and… 740 2 6
Yuuupthatsme RT @Yuuupthatsme: Jestem pod wrażeniem, że lil dicky był w stanie pokazać tak poważny problem w taki przyjemny sposób #WeLoveTheEarth 669 464 1256
RT @Yuuupthatsme: TEGO SIĘ NIE SPODZIEWAŁAM XD #WeLoveTheEarth https://t.co/VuhRNdhcV7 669 70 316
RT @Yuuupthatsme: Miałeś być żyrafą #WeLoveTheEarth https://t.co/0kNCpU8o6q 669 8 56
thremptyworlds RT @thremptyworlds: piosenka jest cudowna, tylko brakuje mi takiego momentu w ktorym wszyscy razem zaspiewaliby refren... #WeLoveTheEarth 629 55 215
typicalbizzzle RT @typicalbizzzle: This song and music video had such a powerful and great message it. It’s a wake up call for the whole woltd to get the… 601 694 1116
liveforshawn02 RT @liveforshawn02: This is one of the most beautiful concepts for a video ever! I’m so proud and thankful of @shawnmendes❤️ @lildickytweet… 578 1 3
aurelialmao RT @aurelialmao: Uważam, że tą piosenkę powinni znać wszyscy, bo może wtedy kogoś ruszy stan naszej planety #EarthMusicVideo #WeLoveTheEarth 572 1 2
jaileystation RT @jaileystation: PERO USTEDES ESCUCHARON A ED SHEERAN SIENDO EL KOALA MAS TIERNO QUE EXISTE #WeLoveTheEarth https://t.co/UvmXmy5E1C 546 332 852
athenajasvier RT @athenajasvier: lil dicky is amazing #WeLoveTheEarth 546 2 0
llostinmyouth RT @llostinmyouth: Ed versione koala è il mio stile di vita dal lunedì alla domenica #WeLoveTheEarth https://t.co/MbhaMaVaRD 520 11 34
MercurySimons RT @MercurySimons: everybody should be listening to this masterpiece, the planet really needs our help and it shouldn't take a song with a… 516 275 489
realestbeach RT @realestbeach: if y’all love the earth, start acting like it. pollution is real and y’all need to start taking it seriously!! #WeLoveTh… 504 354 681
Piatt_Futuro RT @Piatt_Futuro: Edilizia motore di rigenerazione urbana. #4future #19aprile #fridaysforfuture ☀️ #WeLoveTheEarth https://t.co/TdVCrj86L8 427 4 5
RT @Piatt_Futuro: Il nostro "ius soli":  terra, suolo e prodotti agricoli 🇮🇹 nel mondo. #4future #19aprile #fridaysforfuture ☀️ #WeLoveTheE… 427 2 4
RT @Piatt_Futuro: L'ambiente è la leva dello sviluppo economico. #4future #19aprile #fridaysforfuture #WeLoveTheEarth https://t.co/TdVCrj86… 427 5 5
RT @Piatt_Futuro: La persona al centro, l'ambiente intorno. #4future #19aprile ☀️ #fridaysforfuture #WeLoveTheEarth https://t.co/TdVCrj86L8 427 4 6
RT @Piatt_Futuro: Meno gomma, più ferro: trasporti veloci sicuri e non inquinanti. #4future #19aprile #fridaysforfuture ☀️ #WeLoveTheEarth… 427 5 6
RT @Piatt_Futuro: Riscaldamento globale: soluzioni, non fake news! #4future #19aprile #fridaysforfuture ☀️ #WeLoveTheEarth https://t.co/TdV… 427 12 12
RT @Piatt_Futuro: Più mercato e concorrenza per l'accesso di tutti  all'acqua, meno sprechi e inefficienze. #4future #19aprile #fridaysforf… 427 1 1
RT @Piatt_Futuro: Un grande sconto fiscale per l'ambiente! #4future #19aprile #fridaysforfuture ☀️ #WeLoveTheEarth https://t.co/TdVCrj86L8 427 4 6
RT @Piatt_Futuro: Riciclo riuso e termocombustori: Italia pulita, meno malavita. #4future #19aprile #fridaysforfuture ☀️ #WeLoveTheEarth ht… 427 4 8
vanessaibanez_ RT @vanessaibanez_: artists using their platform to spread awareness, kudos!! stream the song #WeLoveTheEarth https://t.co/nID21ksupN 416 1 1
Adryelli_Godoi RT @Adryelli_Godoi: Justin/ Babuíno: Nós vamos morrer?! Lil Dicky: Sabe, Bieber nós podemos morrer. Eu não vou mentir pra você. Há muitas p… 387 629 1095
fayessflatline RT @fayessflatline: This is some true shit #WeLoveTheEarth https://t.co/MLYY7v3JAL 381 8220 16514
brian_prism RT @brian_prism: #ConCalmaRemix & #WeLoveTheEarth  Tonight🔥 https://t.co/EjQbaYZYmu 348 16 22
Clausbelieberj RT @Clausbelieberj: progetto meraviglioso, vederlo mi ha emozionata. coinvolgere così tanti artisti per un buona causa è una cosa bellissim… 337 14 68
ver0017 RT @ver0017: oni doskonale wiedzą, że handwritten przyczyniło się do uratowania naszej planety #WeLoveTheEarth https://t.co/XF0JvxrerA 288 9 42
RT @ver0017: ciekawi mnie na jakiej podstawie dobierali zwierzęta do artystów 😂🤔 #WeLoveTheEarth 288 1 2
dsakrv RT @dsakrv: Lil Dicky - Earth (Official Music Video) https://t.co/M5TtrumWYQ via @YouTube #WeLoveTheEarth 239 1 1
CelebrityArticl RT @CelebrityArticl: #ArianaGrande Opens Up About the Darkish Facet of Performing Her New #music “It Is Hell” #Singer #CelebrityNews #WeLov… 217 3 2
Ws_Vinicius RT @Ws_Vinicius: O Brasil não foi esquecido no churrasco, Rio representando manooo, com os vocais da Ariana de fundo. QUE HINOOOOOOOO EU AM… 215 224 516
sevenyearsbiebs RT @sevenyearsbiebs: oby wiadomość zawarta w piosence trafiła do dużej ilości osób, może dzięki temu świat zacznie się zmieniać na lepsze… 214 546 1083
ShawnDailyJP RT @ShawnDailyJP: Lil Dickyの新曲・チャリティーソング「Earth」 アリアナ・ジャスティン・カニエら名だたるアーティスト達と共にショーンも参加してます。 是非聴いてみて下さい。 #WeLoveTheEarth https://t.co/CKUtq0… 199 1 6
Joprojekt RT @Joprojekt: #WeLoveTheEarth Dire que #LinkinPark a écrit deux albums magnifiques sur l'environnement (pas seulement) #AThousandSuns et #… 182 1 3
justinsmiIxs RT @justinsmiIxs: "Ya sé que no todos somos iguales, pero vivimos en la misma tierra" "¿Vamos a morir?" "Sabes Bieber? No te voy a menti… 171 530 762
jujustinbieeber RT @jujustinbieeber: Que la canción y el video no se quede solo un momento y creamos conciencia del daño que hacemos a los animales, al pla… 167 115 178
sgxjbstylesoft RT @sgxjbstylesoft: la voz de todos esos artistas tan talentosos ha quedado perfecta, amo que se hayan juntando para dejar ese mensaje tan… 156 2 1
jestemzajeta RT @jestemzajeta: uzbierane pieniądze trafiają na fundację Leonardo DiCaprio, która ratuje naszą planetę #WeLoveTheEarth 143 504 1218
RT @jestemzajeta: Shawn jest nosorożecem Halsey lwiątkiem Charlie Puth żyrafą Ed Sheeran koalą Sia kangurem miley słoniem Ariana zebrą K… 143 126 408
itszGabbs RT @itszGabbs: OUÇAM EARTH! O clipe é o incrível, a música mais ainda e todo dinheiro arrecadado com a música será doado para a instituição… 105 72 105
Clem_rocher RT @Clem_rocher: Justin Bieber, Ariana Grande, Wiz Khalifa, Shawn Mendes, Ed Sheeran, Rita Ora... de nombreux artistes se mobilisent autour… 99 30 54
OursPooh RT @OursPooh: we love the earth, it is our planet we love the earth, it is our home #WeLoveTheEarth https://t.co/NXUhU758uQ 98 85 263
soulsfiend RT @soulsfiend: mais les gens qui sont là à se plaindre « gngngn j’aime pas la chanson » vous pouvez connecter vos 2 neurones 2 secondes ?… 82 24 35
introandrew RT @introandrew: #WeLoveTheEarth é un progetto molto importante,oltre ad essere una canzone,vuole lanciare un messaggio,il SALVARE LA TERRA… 81 53 119
twentysevenmoon RT @twentysevenmoon: i recommend you guys go watch Our Planet on netflix. it made me cry and i hope it motivates you to take action on savi… 75 106 274
camillazambett2 RT @camillazambett2: Spero che con questa collaborazione arrivi a tutti il messaggio di salvare la Terra!🌍❤️ #WeLoveTheEarth https://t.co/… 74 3 0
bemybizzle_ RT @bemybizzle_: Justin and Ariana they both sounds so damn good it's just wow !!!! #WeLoveTheEarth https://t.co/9aRwrD6i9J 67 762 1911
xjbtalentedx RT @xjbtalentedx: Yo podría ver y ver éste vídeo nunca me aburriría... ♡ #WeLoveTheEarth https://t.co/HdLb55CNcA 58 63 171
__alfredo30__ RT @__alfredo30__: Questa canzone è bellissima. Speriamo riesca a sensibilizzare più persone possibili su questo enorme pericolo 🌍 #WeLoveT… 55 4 7
protectmayne RT @protectmayne: Earth se tornou minha música preferida junto com o clipe isso simplesmente por passar uma mensagem forte pra gente, eu e… 40 294 562
fabiannn___29 RT @fabiannn___29: Me encantaría tanto que esta canción fuera #1 no solo en USA o UK si no en muchos países del mundo. Ojalá que le den el… 37 5 8
4miraizat RT @4miraizat: ed sheeran(and koala) is my spirit animal #WeLoveTheEarth https://t.co/VYTPuAajM6 28 68 181
LILG96958980 RT @LILG96958980: Me on my way to save the earth after bobbing to the song for a straight hour #WeLoveTheEarth https://t.co/94g0N2SLBM 24 1224 3448
KeyNarumi RT @KeyNarumi: Ini keren sumpah. Pesannya tuh bener bikin lo mikir apa aja yg udah lo lakuin untuk Bumi Kita dengan visual yang menyenangka… 18 1 0
Yuberli_Rosario RT @Yuberli_Rosario: “Todos estos tiroteos, la contaminación. Nos atacamos a nosotros mismos. Vamos a relajarnos, respeta lo que construimo… 17 24 54
bieber_najaFC RT @bieber_najaFC: Com o coração quentinho depois de ver que realmente tem pessoas que se importam com o nosso planeta. #WeLoveTheEarth htt… 14 26 69
khaliqhaiqal_ RT @khaliqhaiqal_: Marvel : "Avengers Endgame is gonna be the most ambitious crossover event in history" Lil Dicky : *hold my beer* @lildi… 13 2151 5487
martyydg RT @martyydg: Semplicemente MERAVIGLIOSO #WeLoveTheEarth https://t.co/m6I2J2soEe 12 2 2
biebermylife946 RT @biebermylife946: Salviamo il posto in cui viviamo,acquistando la canzone daremo una speranza. #WeLoveTheEarth https://t.co/6OmM8oAvhG 12 2 2
Malikjvvd RT @Malikjvvd: Uwuuu uwuuuuuu #WeLoveTheEarth https://t.co/WtVzUrVJW1 1 64 208
In [27]:
%%nose
# %%nose needs to be included at the beginning of every @tests cell

# One or more tests of the student's code
# The @solution should pass the tests
# The purpose of the tests is to try to catch common errors and
# to give the student a hint on how to resolve these errors
    
def strip_comment_lines(cell_input):
    """Returns cell input string with comment lines removed."""
    return '\n'.join(line for line in cell_input.splitlines() if not line.startswith('#'))

last_input = strip_comment_lines(In[-2])


def test_df_creation_command():
    assert 'retweets' in last_input, \
        "The input data for DataFrame creation is not as expected."
    assert 'columns=' in last_input, \
        "The columns parameter is missing."
    assert 'groupby' in last_input, \
        "The groupby method is missing."
    assert 'sum()' in last_input, \
        "The sum method is missing."
    assert 'sort_values' in last_input, \
        "The sort_values method is missing."
    assert 'ascending' in last_input, \
        "The ascending parameter is missing."
    
def test_dataframe():
    correct_dataframe = pd.DataFrame(retweets, columns=['Retweets','Favorites', 'Followers', 'ScreenName', 'Text']).groupby(
    ['ScreenName','Text','Followers']).sum().sort_values(by=['Followers'], ascending=False)
    assert correct_dataframe.equals(df), \
    "The created dataframe does not match the expected dataframe."
Out[27]:
2/2 tests passed

9. Analyzing used languages

🕵️‍♀️ Our table tells us that:

  • Lil Dicky's followers reacted the most — 42.4% of his followers liked his first tweet.
  • Even if celebrities like Katy Perry and Ellen have a huuge Twitter following, their followers hardly reacted, e.g., only 0.0098% of Katy's followers liked her tweet.
  • While Leo got the most likes and retweets in terms of counts, his first tweet was only liked by 2.19% of his followers.

The large differences in reactions could be explained by the fact that this was Lil Dicky's music video. Leo still got more traction than Katy or Ellen because he played some major role in this initiative.


Can we find some more interesting patterns in the data? From the text of the tweets, we could spot different languages, so let's create a frequency distribution for the languages.

In [9]:
# Extracting language for each tweet and appending it to the list of languages
tweets_languages = []
for tweet in tweets:
        tweets_languages.append(tweet['lang'])

# Plotting the distribution of languages
%matplotlib inline
plt.hist(tweets_languages)
Out[9]:
(array([303., 107.,  22.,  14.,  36.,  32.,   3.,   2.,   1.,   2.]),
 array([ 0. ,  1.3,  2.6,  3.9,  5.2,  6.5,  7.8,  9.1, 10.4, 11.7, 13. ]),
 <a list of 10 Patch objects>)
In [29]:
%%nose
# %%nose needs to be included at the beginning of every @tests cell

# One or more tests of the student's code
# The @solution should pass the tests
# The purpose of the tests is to try to catch common errors and
# to give the student a hint on how to resolve these errors

def test_tweet_languages():
    correct_tweet_languages = []
    for tweet in tweets: correct_tweet_languages.append(tweet['lang'])
    assert correct_tweet_languages == tweets_languages, \
    "The tweets_languages variable does not have the expected values."
    
last_value = _

def test_plot_exists():
    assert type(last_value) == type(plt.hist(tweets_languages)), \
    'A plot was not the last output of the code cell.'

def strip_comment_lines(cell_input):
    """Returns cell input string with comment lines removed."""
    return '\n'.join(line for line in cell_input.splitlines() if not line.startswith('#'))

last_input = strip_comment_lines(In[-2])

def test_plot_command():
    assert 'plt.hist(tweets_languages)' in last_input, \
        "We expected the plt.hist() method in your input."   
Out[29]:
3/3 tests passed

10. Final thoughts

🕵️‍♀️ The last histogram tells us that:

  • Most of the tweets were in English.
  • Polish, Italian and Spanish were the next runner-ups.
  • There were a lot of tweets with a language alien to Twitter (lang = 'und').

Why is this sort of information useful? Because it can allow us to get an understanding of the "category" of people interested in this topic (clustering). We could also analyze the device type used by the Twitteratis, tweet['source'], to answer questions like, "Does owning an Apple compared to Andorid influences people's propensity towards this trend?". I will leave that as a further exercise for you!


What an exciting journey it has been! We started almost clueless, and here we are.. rich in insights.

From location based comparisons to analyzing the activity around a tweet to finding patterns from languages and devices, we have covered a lot today — let's give ourselves a well-deserved pat on the back!

Magic Formula = Data + Python + Creativity + Curiosity

In [10]:
# Congratulations!
print("High Five!!!")
High Five!!!
In [31]:
%%nose
# %%nose needs to be included at the beginning of every @tests cell

def test_nothing_task_10():
    assert True, "Nothing to test."
Out[31]:
1/1 tests passed