-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvisual_app.py
133 lines (107 loc) · 3.5 KB
/
visual_app.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import glob
from wordcloud import WordCloud
from wordcloud import ImageColorGenerator
from wordcloud import STOPWORDS
#tag
def tag():
path = r'/hashtag_file.csv/' # use your path
all_files = glob.glob(path + "/*.csv")
for filename in all_files:
df = pd.read_csv(filename, index_col=None, header=0)
df.describe()
import matplotlib.pyplot as plt;plt.rcdefaults()
import numpy as np
import matplotlib.pyplot as plt
objects = df.word
y_pos = np.arange(len(objects))
count = df.word_count
plt.barh(y_pos, count, align='center', alpha=0.5, color="navy")
plt.yticks(y_pos, objects)
plt.xlabel('Count')
plt.title('Top Ten Hashtag Tweets')
plt.savefig('./resource/tag.jpg')
plt.show()
#
text = " ".join(i for i in df.word)
stopwords = set(STOPWORDS)
wordcloud = WordCloud(stopwords=stopwords, background_color="white").generate(text)
plt.figure(figsize=(15, 10))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.savefig('./resource/wordcloud_tag.jpg')
plt.show()
#country
def country():
path = r'/country_file.csv/' # use your path
all_files = glob.glob(path + "/*.csv")
for filename in all_files:
df = pd.read_csv(filename, index_col=None, header=0)
df.describe()
objects = df.country_code
y_pos = np.arange(len(objects))
count = df.tweet_count
plt.barh(y_pos, count, align='center', alpha=0.5, color="brown")
plt.yticks(y_pos, objects)
plt.xlabel('Count')
plt.title('Tweets from Top 10 countries')
plt.savefig('./resource/country.jpg')
plt.show()
text = " ".join(i for i in df.country_code)
stopwords = set(STOPWORDS)
wordcloud = WordCloud(stopwords=stopwords, background_color="white").generate(text)
plt.figure(figsize=(15, 10))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.savefig('./resource/wordcloud_country.jpg')
plt.show()
#device
def device():
path = r'/device_file.csv/' # use your path
all_files = glob.glob(path + "/*.csv")
for filename in all_files:
df = pd.read_csv(filename, index_col=None, header=0)
df.describe()
objects = df.device
y_pos = np.arange(len(objects))
count = df.device_count
plt.barh(y_pos, count, align='center', alpha=0.5, color="yellow")
plt.yticks(y_pos, objects)
plt.xlabel('Count')
plt.title('Tweets originating from devices')
plt.savefig('./resource/device.jpg')
plt.show()
text = " ".join(i for i in df.device)
stopwords = set(STOPWORDS)
wordcloud = WordCloud(stopwords=stopwords, background_color="white").generate(text)
plt.figure(figsize=(15, 10))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.savefig('./resource/wordcloud_device.jpg')
plt.show()
#折线图
def number():
path = r'/number_file.csv/' # use your path
all_files = glob.glob(path + "/*.csv")
for filename in all_files:
df = pd.read_csv(filename, index_col=None, header=0)
df.describe()
objects = df.num
y_pos = objects
length = len(y_pos)
count = []
for i in range(length):
count.append(30*i)
# plt.barh(count, y_pos, alpha=0.5, color="r")
plt.plot(count,y_pos, 's-', color = 'r')
plt.xlabel('Time')
plt.ylabel("Number")
plt.title('number of twits per 30 seconds')
plt.savefig('./resource/number.jpg')
plt.show()
tag()
country()
device()
number()