May-10-2022, 07:14 PM
I have a script which reads in a text/csv files and im saving a filtered version as a new file, can be seen in my last post about deleting after a certain date.. That script works great by providing the date/time as a string value
I would like to be able to automatically pass that value in from the excel file that we are updating with the data..
I have the following code which works to display the values in the console window, but when i try to convert to string or datetime format for my filtering, i get errors
I would like to be able to automatically pass that value in from the excel file that we are updating with the data..
I have the following code which works to display the values in the console window, but when i try to convert to string or datetime format for my filtering, i get errors
df = pd.read_excel(r'C:\Users\myexcel.xlsx) last_date = df.iloc[-1]['Date'] #pandas._libs.tslibs.timestamps.Timestamp last_time = df.iloc[-1]['Time'] #datetime.time If i try this: date_val = (datetime.fromtimestamp(last_date) + ' ' + last_time) i get error: TypeError: an integer is required (got type Timestamp) If i try this: date_val = (last_date + ' ' + last_time) i get error: TypeError: unsupported operand type(s) for +: 'Timestamp' and 'str'In my functioning script im trying to update these lines to use the above variables (the mask line is where im trying to plug the above into)
# THIS CONVERTS THE DATE COLUMN INTO A DATETIME FORMAT df['DT'] = pd.to_datetime(df['Date'] + ' ' + df['Time']) # HERE YOU NEED TO PROVIDE THE DATE YOU WANT TO KEEP GOING FORWARD mask = (df['DT'] > '2022-05-09 2:31 PM')what am i missing or doing wrong? I merely want to take the 2 values i get out of the excel file, to use as the filter that you can see on the "Mask" line above.