Analyzing Social Media Data in Python
Alex Hanna
Computational Social Scientist
#rstats vs #pythonstr.containsSeries string methodSeriescase = False - Case insensitive searchimport pandas as pdtweets = 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