-
Notifications
You must be signed in to change notification settings - Fork 3
/
read_csv.py
34 lines (29 loc) · 983 Bytes
/
read_csv.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
import pandas as pd
import csv
with open('words_for_search.txt', 'r') as f:
words = f.read().splitlines()
print(words)
def findWords(tweet):
for item in words:
if item in tweet:
return True
return False
counter = 0
with open ('new_data.csv', 'w', encoding="utf8") as file_w:
writer = csv.writer(file_w, lineterminator='\r')
head = ['Data', 'Label']
writer.writerow(head)
with open('fake.csv', 'r', encoding="utf8") as file_r:
reader = pd.read_csv(file_r)
for row in reader.itertuples():
tweet = row.Text
if findWords(tweet):
#if row.label == 1 or row.label==0 :
# label = 'Fake'
#else:
# label = 'Real'
tweet = tweet.replace('\n', '')
new_row = tweet, 'Fake'
writer.writerow(new_row)
counter += 1
print(counter)