Category : datetime

I’ve got the following line of code df[‘Sent Date’] = pd.to_datetime(df[‘Sent Date’], format = ‘%-m/%-d/%Y %-I:%M:%S %p’) trying to convert these sort of strings to datetime 1/1/2021 2:20:00 PM I get the following error ‘-‘ is a bad directive in format ‘%-m/%-d/%Y %-I:%M:%S %p’ Also tried import datetime df[‘Sent Date’] = datetime.strptime(df[‘Sent Date’], ‘%-m/%-d/%Y %-I:%M:%S ..

Read more

I am trying to write some content in the hosts file located at address = "C:WindowsSystem32driversetchosts", using the python code, but whenever I run the code, it gets executed with no error but doesn’t write in the hosts file. I have given the administration privilege too. I am not able to understand what is wrong ..

Read more

I have a text file with the following structure: (city, arrival time, departure time ) New-York 14:40 8:00 Los-Angeles 12:00 17:00 San-Diego 14:15 7:10 I find the city I want, and then I need to get the arrival time and the departure time. I can’t get the departure time hours_arrival = re.compile(r”+city+’.*?([0-9]+)’) min_arrival = re.compile(r”+city+’.*?([0-9]+ ..

Read more

I have CSV files that contain some info with datetime in them. I extracted the datetime and converted it into a date like this: daily_readings={"Date":[]} TIME = df.iloc[4,4] report_date = pd.to_datetime(TIME).date() if report_date not in daily_readings[‘Date’]: daily_readings[‘Date’].append(report_date) I imported both datetime and time libraries (not sure if i actually need both). When I print the ..

Read more

I want to loop my code when it reaches the end and move the set time forward by 2 hours whenever the code loops to beginning. How could I do it with existing code? import pynput from datetime import datetime from threading import Timer from pynput.keyboard import Key, Controller import schedule import time x=datetime.today() y=x.replace(day=x.day+0, ..

Read more

I’m getting this error: ValueError: time data ‘2022-01-20T15:30:57.2648531Z’ does not match format ‘%Y-%m-%dT%H:%M:%S.%fZ’ here is my code: import datetime date_string = ‘2022-01-20T15:30:57.2648531Z’ date_format = datetime.datetime.strptime(date_string, "%Y-%m-%dT%H:%M:%S.%fZ") unix_time = datetime.datetime.timestamp(date_format) print(unix_time) I have tested removing the final number in the time data and it worked. It seems you can only have 6 numbers in the millisecond ..

Read more

I have a DataFrame which is: today = dt.now() delta = td(hours=3) new_datetime = today – delta new_datetime_final = new_datetime.strftime("%Y-%m-%d %H:%M") I need to assign a column name to the column which contains the values of "new_datetime.strftime("%Y%m%d%H")" to the new_datetime_final. for example: new_datetime_final dataprocess 2022-01-21 21:00 The value for date will be the same for ..

Read more