Skip to content Skip to sidebar Skip to footer

How To Reorder The Columns Of A Csv?

How can I re-order the columns of a CSV file using Python? These are the first rows of a CSV file I need to change: 03;30269714;Ramiro Alberto;Nederz;active;pgc_gral 03;36185520;An

Solution 1:

Try this:

import csv

with open('yourfile.csv') as f:
    reader = csv.reader(f, delimiter=';')
    for row in reader:
        print(";".join([row[1], row[5], row[2], row[3]]))

Post a Comment for "How To Reorder The Columns Of A Csv?"