Created
January 31, 2017 21:57
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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