I am new to python and my teacher has told me to create a code that can edit a csv file by each field depending on the value in it. Here is a nested list to show the csv file which is split into lists by lines then by elements:
[["A","B","C","D"],["Yes",1,"05/11/2016","0"],["No","12","05/06/2017","1"],["Yes","6","08/09/2017","2"]]
What I am supposed to do is to make a loop which can be used to detect the postions of the elements within the inner list and then change the first element of each list to a "No" if it is a yes ,the 3rd element to today's date if the date stated is at least 6 months back and the last element to a 1 if it is more than 1 ,how am I supposed to do this?
Below is my code:
filename="Assignment_Data1.csv"
file=open(filepath+filename,"r")
reader=csv.reader(file,delimiter=",")
from datetime import datetime
six_months = str(datetime.date.today() - datetime.timedelta(6*365/12-1))
fm_six_months=str(datetime.datetime.strptime(six_months, '%Y-%m-%d').strftime('%d/%m/%Y'))
td=datetime.now()
deDate = str(td)[8:10] + "/"+ str(td)[5:7] + "/"+ str(td)[0:4]
import csv
for row in reader:
for field in row:
if row[2]<=fm_six_months or row[4]>50 or row[2]<10:
row[3]=deDate
row[4]=0
row[2]=100
Basically what I am trying to do is to replace the fields that have the above stated conditions with want I want through a loop ,is it possible?