Book Image

Mastering Social Media Mining with Python

By : Marco Bonzanini
Book Image

Mastering Social Media Mining with Python

By: Marco Bonzanini

Overview of this book

Your social media is filled with a wealth of hidden data – unlock it with the power of Python. Transform your understanding of your clients and customers when you use Python to solve the problems of understanding consumer behavior and turning raw data into actionable customer insights. This book will help you acquire and analyze data from leading social media sites. It will show you how to employ scientific Python tools to mine popular social websites such as Facebook, Twitter, Quora, and more. Explore the Python libraries used for social media mining, and get the tips, tricks, and insider insight you need to make the most of them. Discover how to develop data mining tools that use a social media API, and how to create your own data analysis projects using Python for clear insight from your social data.
Table of Contents (15 chapters)
Mastering Social Media Mining with Python
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface

Analyzing tweets - entity analysis


This section is all about analyzing entities in tweets. We're going to perform some frequency analysis using the data collected in the previous section. Slicing and dicing this data will allow users to produce some interesting statistics that can be used to get some insights on the data and answer some questions.

Analyzing entities such as hashtags is interesting as these annotations are an explicit way for the author to label the topic of the tweet.

We start with the analysis of the tweets by Packt Publishing. As Packt Publishing supports and promotes open source software, we are interested in finding what kind of technologies are mentioned often by Packt Publishing.

The following script extracts the hashtags from a user timeline, producing a list of the most common ones:

# Chap02-03/twitter_hashtag_frequency.py 
import sys 
from collections import Counter 
import json 
 
def get_hashtags(tweet): 
  entities = tweet.get('entities', {}) 
  hashtags = entities...