outputfile = open('test.csv', 'w')
reps = {'"NAN"': 'NAN', '"': '', '0-': '0,', '1-': '1,', '2-': '2,', '3-':
    '3,', '4-': '4,', '5-': '5,', '6-': '6,', '7-': '7,', '8-': '8,', '9-':
    '9,', ' ': ',', ':': ','}
for i in range(4):
    next(inputfile)
for line in inputfile:
    outputfile.writelines(data_parser(line, reps))
inputfile.close()
outputfile.close()
Text File Parsing with Python