-
Notifications
You must be signed in to change notification settings - Fork 15
/
preprocessing.py
37 lines (30 loc) · 1007 Bytes
/
preprocessing.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
import csv
import json
import pandas as pd
from pandas.io.json import json_normalize
import tensorflow as tf
flags = tf.flags
FLAGS = flags.FLAGS
## Required parameters
flags.DEFINE_string(
"inpath", None,
"The input data dir. Should contain the .tsv files (or other data files) "
"for the task.")
flags.DEFINE_string(
"outpath", None,
"The input data dir. Should contain the .tsv files (or other data files) "
"for the task.")
flags.DEFINE_bool(
"istrain", False,
"The input data dir. Should contain the .tsv files (or other data files) "
"for the task.")
def json_to_csv(inpath, outpath, is_train=False):
with open(inpath) as data_file:
data = json.load(data_file)
if is_train:
json_normalize(data).to_csv(outpath, index=False)
else:
json_normalize(data, 'paragraphs', ['__id__','question','title']).to_csv(outpath, index = False)
return outpath
if __name__ == "__main__":
json_to_csv(FLAGS.inpath, FLAGS.outpath, FLAGS.istrain)