Skip to content

Finding the most favorite tweet

Shimakh edited this page Feb 21, 2018 · 1 revision

Find the most favorite tweet

  1. Getting the data from mongo

pip install pymongo

import pandas as pd ​​

from pymongo import MongoClient

%matplotlib inline

mongo_client = MongoClient('this-mongo.cc', 27016)

database_reference = mongo_client.twitter

  1. Assigning users

​users_reference = database_reference.users 3. Counting the tweets

​users_reference.count()

  1. Using pipline operation

​PROJECT = "$project" MATCH = "$match" LIMIT = "$limit" UNWIND = "$unwind" GROUP = "$group" SORT = "$sort" COUNT = "$count"

5.Finding the most favorites counts

​fav_count_max = pd.DataFrame(list(users_reference.aggregate([ {'$group':

{ "_id" : "$favorites_count" , 'favourites_count' : {'$max': '$favourites_count'} }}

6.Displaying the most favorite count

fav_count_max

7.Displaying the top 3

fav_count.head(3)

Clone this wiki locally