-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcsv2hdf5.py
37 lines (29 loc) · 938 Bytes
/
csv2hdf5.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
# coding: utf-8
from argparse import ArgumentParser
from utils import read_as_pandas, save_pandas, map_by_chunk
def csv2hdf5(infile, outfile, append):
"""
csv to hdf5
:param infile:
:param outfile:
:return:
"""
if not append:
df = read_as_pandas(infile)
save_pandas(df, outfile)
else:
map_by_chunk(
filename=infile,
read_func=lambda filename: read_as_pandas(filename=filename, by_chunk=True),
save_func=lambda df: save_pandas(df, filename=outfile, append=True),
map_func=None,
)
def main(args):
csv2hdf5(args.input_file, args.out_file, args.by_chunk)
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument("--input_file", required=True)
parser.add_argument('--output_file', required=True)
parser.add_argument('--by_chunk', type=bool)
args = parser.parse_args()
main(args)