MH-P2/src/preprocessing.py

16 lines
367 B
Python
Raw Normal View History

2021-04-29 12:33:46 +02:00
from pandas import read_table
def read_header(filename):
with open(filename, "r") as f:
header = f.readline().split()
return int(header[0]), int(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