Created
February 9, 2011 11:05
-
-
Save noomz/818315 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import csv | |
def clean_cells(row): | |
row_out = [] | |
for cell in row: | |
cell = cell.strip().strip(' ').strip('-').strip() | |
if cell == '*': cell = '' | |
if cell == 'N/A': cell = '' | |
row_out.append(str(cell)) | |
return row_out | |
reader = csv.reader(open('project.csv', 'rb')) | |
writer = csv.writer(open('output.csv', 'wb'), delimiter=',', quotechar='"', quoting=csv.QUOTE_NONNUMERIC) | |
# fetch out header row | |
reader.next() | |
row = [] | |
last_row = [] | |
last_id = 0 | |
for row in reader: | |
row = clean_cells(row); | |
if row[0] != last_id and row[0] != '': | |
if last_id != 0: | |
writer.writerow(last_row) | |
print '# just writerow #' + last_row[1] | |
last_row = row | |
else: | |
for i, cell in enumerate(row): | |
if cell: | |
last_row[i] += '|' + cell | |
print '# T_T #' + last_row[1] | |
last_id = last_row[0] | |
exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment