Jul-24-2018, 07:56 AM
Hello,
i have a csv file. It represents events that happen in France. One column contains date written like so 'YYYY-MM-DD'. I want to delete every row that has a date difference of at least 60 days from today.
I have created this program that from the string 'YYYY-MM-DD' return the difference in days from today.
Thank you
i have a csv file. It represents events that happen in France. One column contains date written like so 'YYYY-MM-DD'. I want to delete every row that has a date difference of at least 60 days from today.
I have created this program that from the string 'YYYY-MM-DD' return the difference in days from today.
date ='2018-08-26'
liste = date.split('-')
print(liste)
liste2 = []
liste2.append(int(liste[0]))
liste2.append(int(liste[1].replace('0','')))
liste2.append(int(liste[2].replace('0','')))
print(liste2)
test = datetime.now() - datetime(liste2[0], liste2[1], liste2[2])
print(test)
if test[0] > 60 :
print("delete")And I get this error:['2018', '08', '26']
[2018, 8, 26]
-33 days, 9:52:04.046700
Traceback (most recent call last):
File "untitled2.py", line 20, in <module>
if test[0] > 60 :
TypeError: 'datetime.timedelta' object is not subscriptableI don't know how to "extract" the number of days, do you have any idea?Thank you
