Skip to content

Instantly share code, notes, and snippets.

@milothiesen
Created January 31, 2017 21:57
Show Gist options
  • Save milothiesen/06a6f3836dbc8b02db018920285e3794 to your computer and use it in GitHub Desktop.
Save milothiesen/06a6f3836dbc8b02db018920285e3794 to your computer and use it in GitHub Desktop.
Open a csv, add a new column, concatenate information from various rows, insert desired concat into last cell in row
#!/usr/bin/python
import csv
import sys
filename = sys.argv[1]
# destination = sys.argv[2]
titles = []
met = " MET "
image_url = []
newfilename = ""
with open(filename) as csvinput:
reader = csv.reader(csvinput)
with open('output.csv', 'w') as csvoutput:
writer = csv.writer(csvoutput, lineterminator='\n')
reader = csv.reader(csvinput)
all = []
row = next(reader)
row.append('Filename')
all.append(row)
for row in reader:
newfilename = (row[7]) + met + (row[44].rsplit('/', 1)[-1])[:-4]
# print newfilename
row.append(newfilename)
all.append(row)
writer.writerows(all)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment