-
Notifications
You must be signed in to change notification settings - Fork 1
/
concat.py
30 lines (26 loc) · 1.07 KB
/
concat.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
import pandas as pd
import argparse
import json
def concat_csv(Mpath, Cpath, dirSave):
main = pd.read_csv(Mpath,sep=" ")
labels = pd.read_csv(Cpath, sep=" ")
df = pd.concat([main, labels], axis = 1)
df.to_csv(dirSave, sep=",", index=False)
def concat_json(Lpath, Apath, dirsave):
with open(dirsave, "w") as save:
Lore = json.load(open(Lpath,"r"))
Anchor = json.load(open(Apath,"r"))
concat = Lore + Anchor
json.dump(concat, save, indent=2)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="concat csv", formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("--type", type=str, default=None)
parser.add_argument("--first", type=str, default=None)
parser.add_argument("--second" , type=str, default=None)
parser.add_argument("--save-dir", type=str, default=None)
args = parser.parse_args()
match args.type:
case "csv":
concat_csv(args.first, args.second, args.save_dir)
case "json":
concat_json(args.first, args.second, args.save_dir)