python-datetime

Add incrementing seconds to DateTime column Pandas

Add incrementing seconds to DateTime column Pandas Question: I have the following type of df: Date_time Col1 0 2023-03-04 10:30:00 10 1 2023-03-04 10:30:00 11 2 2023-03-04 10:30:00 21 3 2023-03-04 10:30:00 54 4 2023-03-04 10:30:00 12 5 2023-03-04 10:30:00 13 6 2023-03-04 10:30:00 21 … 58 2023-03-04 10:30:00 22 59 2023-03-04 10:30:00 21 60 …

Total answers: 1

Python datetime format string excluding zeros

Python datetime format string excluding zeros Question: str(datetime.date.today()) I get: 2023-04-01 I need: 2023-4-1 If I format it to remove zeros then I will face an issue if the date is 2023-10-20 How can I do it quick and simple. I need it as a string. Asked By: CODComputerAtWar || Source Answers: You can always …

Total answers: 2

Merge 'Date' and 'Time' columns with specific format into 'Date_Time' column Pandas

Merge 'Date' and 'Time' columns with specific format into 'Date_Time' column Pandas Question: I have a df with Time and Date columns in this specific format. Time Date 213919 220806 220905 220806 225351 220806 4101 220806 12037 220806 The format of Time is: hhmmss The format of Time is a bit strange, the reading must …

Total answers: 2

Date time difference in minutes python

Date time difference in minutes python Question: I’m new to python and tiring to calculate time difference in minutes. Times are in slightly two different formats. I have tried below to format but did not got it correctly from datetime import datetime start = "2023-05-21T11:40:54.532203+00:00" end = "2023-05-21T11:45:00+00:00" starttime=datetime.strptime(start , "%Y-%m-%dT%H:%M:%S:%f%z’") endtime=datetime.strptime(end , "%Y-%m-%dT%H:%M:%S:%f%z’") Asked …

Total answers: 2

TypeError: cannot convert the series to <class 'int'> when process dataframe

TypeError: cannot convert the series to <class 'int'> when process dataframe Question: I want to use is_holiday() in chinesecalendar library to judge holidays based on the information in the time column of dataframe (datetime.date is required to be passed). I extract three integers from the dataframe and combine them into datetime.date, but TypeError: cannot convert …

Total answers: 2

Dataframe of start and end dates into sum of days in an array of periods

Dataframe of start and end dates into sum of days in an array of periods Question: I have a pandas data frame of start and end dates for contracts. I want to work out the number of in force contract days for all periods (e.g. months) covered by the contracts. Example input: start_date end_date 0 …

Total answers: 1

PYTHON changing date format using datetime

How to change date format using datetime from openpyxl? Question: I would like to create a function that will convert the date from a string variable to a date format for further processing. The problem is that I managed to isolate the fields where there is no entry "date" : [], but I can’t create …

Total answers: 1