Skip to content

Instantly share code, notes, and snippets.

@alex-hofsteede
Last active March 11, 2016 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alex-hofsteede/dec3be4b0fccbd682124 to your computer and use it in GitHub Desktop.
Save alex-hofsteede/dec3be4b0fccbd682124 to your computer and use it in GitHub Desktop.
A B C 1 2 3
Z Y X 1 2 3
import csv
import sys
with open(sys.argv[1], "rU") as f:
reader = csv.reader(f)
writer = csv.writer(sys.stdout)
split = 4 # how many common columns at the beginning
for i, row in enumerate(reader):
if i == 0:
header = row
else:
for x in range(split, len(row)):
writer.writerow(row[1:split] + [header[x]] + [row[x]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment