-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample_K_data_points.py
More file actions
36 lines (31 loc) · 973 Bytes
/
sample_K_data_points.py
File metadata and controls
36 lines (31 loc) · 973 Bytes
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
import argparse
import csv
ap = argparse.ArgumentParser()
ap.add_argument("-k", "--numPoints", help="Number of questions to sample")
args = vars(ap.parse_args())
k = args["numPoints"]
print("k", k)
if k:
NUM_QUESTION_PROCESSED = int(k)
else:
NUM_QUESTION_PROCESSED = 200000
print("NUM_QUESTION_PROCESSED", NUM_QUESTION_PROCESSED)
f = open('topkQuestions', 'w', encoding='latin1')
count = 0
with open('./data/Questions.csv', encoding='latin1') as ques_csv:
reader = csv.reader(ques_csv, delimiter=',')
next(reader, None) # skip the headers
for row in reader:
# Id Field
doc_id = row[0]
# Title field
title = row[5]
# write to file
f.write(doc_id + "," + title + "\n")
count += 1
if count % 100 == 0:
print("[INFO] {} number of questions processed".format(count))
if count == NUM_QUESTION_PROCESSED:
break
print("[INFO] Sample completed")
f.close()