I have tried
num_columns = 982
def transform_row(row):
#row = row.split('\n') # split on new line
row = row.split(',') # split on commas
row = [i.split() for i in row if i!='5'] # remove 5s
row += ['0']*(num_columns - len(row)) # add 0s to end
return ','.join(row)
#and then apply this over the csv.
out = open('outfile.csv', 'w')
for row in open('dataset_TR1.csv'):
out.write(transform_row(row))
In essence, I want to remove all 5s from each row in a csv file and replace the missing length with trailing 0s bewtween columns 982 and 983. However, using the data file from http://www.filedropper.com/datasettr1 , this only seems to write everything to one row and the output is not as expected.