From 46efa13c5b7f8c1c4c1e82f51f860fea25892c0a Mon Sep 17 00:00:00 2001 From: coolneng Date: Mon, 15 Mar 2021 18:19:59 +0100 Subject: [PATCH] Implement file parsing --- src/preprocessing.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/preprocessing.py diff --git a/src/preprocessing.py b/src/preprocessing.py new file mode 100644 index 0000000..e1dc958 --- /dev/null +++ b/src/preprocessing.py @@ -0,0 +1,24 @@ +from sys import argv +from pandas import read_table + + +def read_header(filename): + with open(filename, "r") as f: + header = f.readline().split() + return header[0], header[1] + + +def parse_file(filename): + n, m = read_header(filename) + df = read_table( + filename, names=["source", "destination", "distance"], sep=" ", skiprows=[0] + ) + return n, m, df + + +def main(): + parse_file(argv[1]) + + +if __name__ == "__main__": + main()