I have a csv file that I need to change the date value in each row. The date to be changed appears in the exact same column in each row of the csv.
import csv
firstfile = open('example.csv',"r")
firstReader = csv.reader(firstfile, delimiter='|')
firstData = list(firstReader)
DateToChange = firstData[1][25]
ChangedDate = '2018-09-30'
for row in firstReader:
for column in row:
print(column)
if column==DateToChange:
#Change the date
outputFile = open("output.csv","w")
outputFile.writelines(firstfile)
outputFile.close()
I am trying to grab and store a date already in the csv and change it using a for loop, then output the original file with the changed dates. However, the code above doesn't seem to do anything at all. I am newer to Python so I might not be understanding how to use a for loop correctly.
Any help at all is greatly appreciated!
DETAIL|2507|2018-10-13|7|TESTUSER23|User|Test|J|AP|10001|||||||||JSHDKF02SD45FSD|11315|BF|USD|UNITED STATES|2018-10-04|2018-09-07|2018-09-30|September 2018|Y|N|N|Above is a same row I am importing @Tomothy32 The problem is that the date I am trying to replace could appear multiple times outside the column I am trying to replace