Analyzing Social Media Data in Python
Alex Hanna
Computational Social Scientist
#rstats
vs #python
str.contains
Series
string methodSeries
case = False
- Case insensitive searchimport pandas as pd
tweets = pd.DataFrame(flatten_tweets(companies_json))
apple = tweets['text'].str.contains('apple', case = False)
print(np.sum(apple) / tweets.shape[0])
0.112
apple = tweets['text'].str.contains('apple', case = False) for column in ['extended_tweet-full_text', 'retweeted_status-text', 'retweeted_status-extended_tweet-full_text']: apple = apple | tweets[column].str.contains('apple', case = False)
print(np.sum(apple) / tweets.shape[0])
0.12866666666666668
Analyzing Social Media Data in Python