-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrefine.py
63 lines (59 loc) · 2.16 KB
/
refine.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
import csv
import random
states = ['ak','usb','usc','usd']
currentFile = 0
fileRoot = 'data/ss13p'
priority1 = []
priority2 = []
priority3 = []
def reduceDataByColumn(infile,outfile):
existingTweets = []
with open(outfile,'wb') as outputFile:
spamwriter = csv.writer(outputFile)
with open(infile, 'rb') as csvfile:
spamreader = csv.reader(csvfile)
# headerDictionary = replaceHeaderCodes()
for row in spamreader:
newRow = []
newRowText = ""
for column in row:
if len(column)>6:
newRow.append(column)
newRowText+=column
shortTweet = ""
rowLength = len(newRow)
sampling = random.sample(range(1, len(newRow)), rowLength-1)
for i in sampling:
shortTweet += str(newRow[i])
while len(newRowText) > 140 and rowLength > 3:
sampling = random.sample(range(1, len(newRow)), rowLength-1)
rowLength = rowLength-1
#print sampling
shortTweet = ""
for i in sampling:
shortTweet += str(newRow[i])
#print len(shortTweet)
#print newLine
#print shortTweet
if shortTweet in existingTweets:
print "repeat"
else:
spamwriter.writerow([shortTweet])
infile = fileRoot+states[currentFile]+"_filledin.csv"
outfile = fileRoot+states[currentFile]+"_refined.csv"
reduceDataByColumn(infile,outfile)
maxLength = 31
def findCompleteRow(infile):
maxLength = 0
with open(infile, 'rb') as csvfile:
spamreader = csv.reader(csvfile)
# headerDictionary = replaceHeaderCodes()
for row in spamreader:
rowLength = len(row)
for column in row:
if column == "":
rowLength = rowLength-1
if rowLength > 30:
print row
print maxLength
#findCompleteRow(infile)