May-06-2022, 07:45 AM
(This post was last modified: May-06-2022, 07:46 AM by Pedroski55.)
I sometimes do a similar thing in MySQL, if I forget to set the correct date first.
As far as I know, you can compare dates directly。
Assuming your data is in ascending order, you can find the position where you want to cut off an take a slice.
As far as I know, you can compare dates directly。
Assuming your data is in ascending order, you can find the position where you want to cut off an take a slice.
def myApp(): import csv, glob path2file = '/home/pedro/myPython/csv/' files = glob.glob(path2file + '*.csv') for f in files: print('The files are', f) myfile = input('Copy and paste a file here ... ') with open(myfile) as infile: my_csv_read = csv.reader(infile) data = [] # csv reader is burned as soon as you read it, so make a list, lasts longer for line in my_csv_read: data.append(line) print(line) # working principle x = '2022-04-25 7:07 PM' y = '2022-04-25 7:08 AM' if x > y: print('x is older than y') if x < y: print('x is younger than y') nums2delete = [] # start at 1 if you have a headers row for i in range(1, len(data)): if data[i][0] >= '2022-04-25 7:07 AM': break wanted = data[0:i]