Skip to content

Instantly share code, notes, and snippets.

@pontikos
Created January 16, 2015 17:19
Show Gist options
  • Select an option

  • Save pontikos/cb5adbff97b3254abf4d to your computer and use it in GitHub Desktop.

Select an option

Save pontikos/cb5adbff97b3254abf4d to your computer and use it in GitHub Desktop.
Join lines of CSV file on column field number specified (starting at 0).
import sys
i=int(sys.argv[1])
d=dict()
for l in sys.stdin.readlines():
l=l.strip().split(',')
k=l.pop(i)
d[k]=d.get(k,[])+l
for k in d:
print ','.join([k]+d[k])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment