I need to manipulate the first element(which is an integer from 1 - 1000) of a csv file while also performing other operations.
Right now i have this code which prints a new row on every third row. But i also want to manipulate the first element with a counter on every third row by replacing the first element with a counter.
How my csv file after it is manipulated looks today:
1, information, info
2, info, info
, , ,
3, info, info
How i want it to look after it is manipulated
1, info, info
2, info, info
, , ,
4, info, info
My code:
with open("mycsvfile.csv", 'r') as infile:
readstream = csv.reader(infile, delimiter=',')
with open("output.csv", 'wt') as output:
outwriter = csv.writer(output, delimiter=',')
i = 0
#I want to manipulate the first element of the .csv-file here
next(readstream) #to skip first row
for row in readstream:
outwriter.writerow(row)
i += 1
if i % 2 == 0:
outwriter.writerow([])
.csvlooks like ? ^^.csv? Maybe with my own example it works ^^ Instead of adding some more words, you could've just add a part of the csvrow[0] = ijust beforeoutwriter.writerow(row)? I think you're working with a nested list so you can redefine items in that list by their index