Hello, I am trying to swap the values in columns 1 and 2 respectively from an input file (.csv) and have them displayed swapped in the output file (the other columns are still the same). Any help would be appreciated. For this assignment, I'm not allowed to use Pandas.
This is my current code:
This is my current code:
def re_order(in_file, out_file): with open(in_file, 'r', newline='') as in_file_handle: reader = csv.reader(in_file_handle) columns = [1, 0] for row in reader: content = [row[i] for i in columns] with open(out_file, 'w', newline='') as out_file_handle: writer = csv.writer(out_file_handle) writer.writerow(content)