-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwcloud.py
67 lines (53 loc) · 1.94 KB
/
wcloud.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
from nltk.corpus import stopwords
import matplotlib.pyplot as plt
import wordcloud
from start import *
stop_words = set(stopwords.words('english')) #list of stop words
file = ' '.join(dft.text.values)# Use this to read file content as a stream:
werd = list()
for r in file.split():
#print(r)
if not r in stop_words: #removing all stop words to build the word cloud
werd.append(r)
realcloud = wordcloud.WordCloud(width = 1000, height = 500).generate(' '.join(werd))
plt.figure(figsize=(15,8))
plt.title('Word cloud for articles labeled as real')
plt.imshow(realcloud)
plt.axis("off")
plt.show()
file = ' '.join(dff.text.values)# Use this to read file content as a stream:
werd = list()
for r in file.split():
#print(r)
if not r in stop_words: #removing all stop words to build the word cloud
werd.append(r)
fakecloud = wordcloud.WordCloud(width = 1000, height = 500).generate(' '.join(werd))
plt.figure(figsize=(15,8))
plt.title('Word cloud for articles labelled as fake')
plt.imshow(fakecloud)
plt.axis("off")
plt.show()
file = ' '.join(dff.title.values)# Use this to read file content as a stream:
werd = list()
for r in file.split():
#print(r)
if not r in stop_words: #removing all stop words to build the word cloud
werd.append(r)
fakecloud = wordcloud.WordCloud(width = 1000, height = 500).generate(' '.join(werd))
plt.figure(figsize=(15,8))
plt.title('Word cloud for headlines labelled as fake')
plt.imshow(fakecloud)
plt.axis("off")
plt.show()
file = ' '.join(dft.title.values)# Use this to read file content as a stream:
werd = list()
for r in file.split():
#print(r)
if not r in stop_words: #removing all stop words to build the word cloud
werd.append(r)
fakecloud = wordcloud.WordCloud(width = 1000, height = 500).generate(' '.join(werd))
plt.figure(figsize=(15,8))
plt.title('Word cloud for headlines labelled as real')
plt.imshow(fakecloud)
plt.axis("off")
plt.show()