-
Notifications
You must be signed in to change notification settings - Fork 2
Finding the most favorite tweet
Shimakh edited this page Feb 21, 2018
·
1 revision
- 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
- Assigning users
users_reference = database_reference.users
3. Counting the tweets
users_reference.count()
- 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)