-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathingestion.py
More file actions
45 lines (33 loc) · 1.21 KB
/
ingestion.py
File metadata and controls
45 lines (33 loc) · 1.21 KB
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
"""
Python script meant to ingest new data.
"""
import pandas as pd
import glob
import logging
import json
import os
import sys
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
with open("config.json", "r") as f:
"""
Load config.json and get input and output paths.
"""
config = json.load(f)
input_folder_path = config["input_folder_path"]
output_folder_path = config["output_folder_path"]
def merge_multiple_dataframe():
"""
Check for datasets, compile them together, and write to an output file.
"""
csv_files = glob.glob("%s/*.csv" % input_folder_path)
df = pd.concat(map(pd.read_csv, csv_files), ignore_index=True)
df.drop_duplicates(inplace=True)
df.to_csv("%s/finaldata.csv" % output_folder_path, index=False)
with open(os.path.join(output_folder_path, "ingestedfiles.txt"), "w") as report_file:
for line in csv_files:
report_file.write(line + "\n")
if __name__ == "__main__":
logging.info("Running Ingestion!")
merge_multiple_dataframe()
logging.info("Artifacts output written in ingesteddata/finaldata.csv")
logging.info("Artifacts output written in ingesteddata/ingestedfiles.csv")