import csv w = csv.writer(open("accounts.csv", "w", newline="")); w.writerow(["account", "name", "balance", "opened"]) for line in open("listing.txt"): if not line[:8].strip().isdigit(): continue b = line[30:42].strip(); neg = b.endswith("-"); b = float(b.rstrip("-").replace(",", "")) d = line[42:50] w.writerow([line[:8], line[8:30].strip(), f"{-b if neg else b:.2f}", f"{d[:4]}-{d[4:6]}-{d[6:]}"])