Freewind
Freewind

Reputation: 198318

How to move column or swap two columns with csvkit?

I'm using csvkit to manipulate csv files, but can't find how to do this:

  1. move one column before or after another column
  2. swap two columns but keep others unchanged

Does someone know how to do it?

Upvotes: 3

Views: 2043

Answers (2)

Yisrael Dov
Yisrael Dov

Reputation: 2449

You could use csvcut

csvcut -c column_c,column_a data.csv > new.csv

Or csvsql

csvsql --table=x --query "select column_c,column_a from x" data.csv

If you are used to sql queries the second might be easier for you.

Upvotes: 3

Roland Smith
Roland Smith

Reputation: 43523

According to the documentation you linked to, csvcut can do the job. A disadvantage would be that you have to list all of the columns.

An alternative would be to use pandas.

Upvotes: 1

Related Questions