1
0
Fork 0
mirror of https://github.com/Findus23/column-transformation.git synced 2024-09-20 15:53:46 +02:00
column-transformation/script.py
2021-04-27 19:04:08 +02:00

27 lines
790 B
Python

from pathlib import Path
from sys import argv
inputfile = Path(argv[1])
outputfile = Path(argv[2])
counter = {}
with inputfile.open() as ip:
next(ip) # skip the first line
for line in ip: # go through all lines
columns = line.split("\t")
value = int(columns[1])
names = columns[0].split("|")
for name in names:
if name not in counter:
# if this is the first time the name showed up,
# set the counter to the value
counter[name] = value
else:
# otherwise increase it by the value
counter[name] += value
print(counter)
with outputfile.open("w") as wf:
for name, count in counter.items():
wf.write(f"{name};{count}\n") # Cinema;4