-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTwitter_Hashtag_Analysis.py
47 lines (39 loc) · 1.44 KB
/
Twitter_Hashtag_Analysis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import tweepy
import csv
import pandas as pd
####input your credentials here
consumer_key = 'Z0bEpYrdrA91bIqFhHIUN78Oz'
consumer_secret = 'g5AudmBzHv1Y9eAjixXtV91TrgtCpX6NExb2QhNTV1fH3QAGcj'
access_token = '957223669738045440-NI42JKqdmyN7HinPszkBQzev4L1It9n'
access_token_secret = 'aGoJRuSkDguVnoSQ6SR87eVPcou5BcgR6gLdnwkS547n8'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth,wait_on_rate_limit=True)
#####United Airlines
# Open/Create a file to append data
csvFile = open('tweets.csv', 'w')
#Use csv Writer
csvWriter = csv.writer(csvFile)
for tweet in tweepy.Cursor(api.search,q="#ExploreMLBLR",count=100,
lang="en",
since="2019-10-03").items():
#print (tweet.created_at, tweet.text)
csvWriter.writerow([tweet.user.screen_name, tweet.text.encode('utf-8')])
csv = pd.read_csv('tweets.csv',names=["Username","Tweet"])
count = csv['Username'].value_counts()[:]
csv.head(10)
top2 = count.head(2)
top2
import matplotlib.pyplot as plt
colors = ["#E13F29", "#D69A80", "#D63B59", "#AE5552", "#CB5C3B", "#EB8076", "#96624E"]
top2.plot.pie(y=top2.index,
shadow=False,
colors=colors,
radius = 1000,
explode=(0, 0), # exploding 'Friday'
startangle=90,
autopct='%1.1f%%',
textprops={'fontsize': 10})
plt.axis('equal')
plt.tight_layout()
plt.show()