Have a csv file called 'data.csv' in the following format:
read lines in
with open('data.csv', 'r') as fi: lines = [[i.strip() for i in line.strip().split(',')] \ for line in fi.readlines()] col = ['test4', 4, 7, 10]
Concatenate each row with corresponding element of
col. Using enumerate to help keep track of which list index to use.
new_lines = [line + [str(col[i])] for i, line in enumerate(lines)]
Output to file
with open('adjusted.csv', 'w') as fo: for line in new_lines: fo.write(','.join(line) + '\n')