Skip to content
Advertisement

Tag: datetime

Prepopulate a DateTimeField in Django Rest Framework

I’m using a Django Rest Framework Serializer. Fields allow the initial parameter to be passed, which prepopulates a values in the browsable API. In the docs, the DateField is used as an example with an initial value of datetime.date.today. I would like to prepopulate a DateTimeField. However, the initial value is being ignored and I see mm/dd/yyyy, –:– — as

Change date format of these string using Python

I have a string from a pdf that I want to transform it to the date format that I want to work with later, the string is 05Dec22 how can I change it to 12/05/2022? This is what i tried so far Answer If you execute the code you’ll get the following error, this is because your time string is

Why are python dates such a mess and what can I do about it?

A common source of errors in my Python codebase are dates. Specifically, the different implementations of dates and datetimes, and how comparisons are handled between them. These are the date types in my codebase You can print them to see: Is there a canonical date representation in Python? I suppose x7: datetime.date is probably closest… Also, note comparisons are a

Remove part of a string from pd.to_datetime() unconverted values

I tried to convert a column of dates to datetime using pd.to_datetime(df, format=’%Y-%m-%d_%H-%M-%S’) but I received the error ValueError: unconverted data remains: .1 I ran: to identify the problem. 119/1037808 dates in the date column have an extra “.1” at the end of them. Other than the “.1”, the dates are fine. How can I remove the “.1” from the

How to datetime parse a non-standardized time format

I would like to create datetime objects from a list of string timecodes like these. However, parse interprets incorrectly for my use case. The list above comes from YouTube’s transcript timecodes. When copied from the site, they use a variable format to designate hours, minutes, and time, based on elapsed time: and parse results in (comments are my interpretations): i.e.

Dataframe conditions syntax

I have a mystery error on line 13 of this program. I’m trying to select all the times between 22.00 and 23.00. I’ve tried with and without datetime, with and without apostrophes, but I get the same error every time: “SyntaxError: invalid syntax” The csv file is 8 columns and ‘complaint_time’ is in the format 12:22:01 AM. What am I

Advertisement