datetime-format

How to convert time zone of datetime column in pandas, then remove time zone?

How to convert time zone of datetime column in pandas, then remove time zone? Question: I have a column (non-index column) that has datetimes inside it. For example, the first five entries look something like this: [Timestamp(‘2018-11-15 19:57:55’), Timestamp(‘2018-11-15 19:59:46’), Timestamp(‘2018-11-15 20:00:59’), Timestamp(‘2018-11-15 20:01:41’), Timestamp(‘2018-11-15 20:01:54’)] I want to convert the entries from UTC to …

Total answers: 1

Datetime format in flask marshmallow schema

Datetime format in flask marshmallow schema Question: I want to apply a custom DateTime format for the data retrieved from model using the Schema in flask marshmallow. Currently using the schema like: class ScheduleListSchema(ma.Schema): class Meta: fields = (‘id’, ‘start_time’, ‘end_time’) In this start_time in format of 2018-12-05T03:00:00+00:00 So I want to create a custom …

Total answers: 3

How to convert datetime object to milliseconds

How to convert datetime object to milliseconds Question: I am parsing datetime values as follows: df[‘actualDateTime’] = pd.to_datetime(df[‘actualDateTime’]) How can I convert this datetime objects to milliseconds? I didn’t see mention of milliseconds in the doc of to_datetime. Update (Based on feedback): This is the current version of the code that provides error TypeError: Cannot …

Total answers: 7

python strptime format with optional bits

python strptime format with optional bits Question: Right now I have: timestamp = datetime.strptime(date_string, ‘%Y-%m-%d %H:%M:%S.%f’) This works great unless I’m converting a string that doesn’t have the microseconds. How can I specify that the microseconds are optional (and should be considered 0 if they aren’t in the string)? Asked By: Digant C Kasundra || …

Total answers: 8

Convert DataFrame column type from string to datetime

Convert DataFrame column type from string to datetime Question: How can I convert a DataFrame column of strings (in dd/mm/yyyy format) to datetime dtype? Asked By: perigee || Source Answers: The easiest way is to use to_datetime: df[‘col’] = pd.to_datetime(df[‘col’]) It also offers a dayfirst argument for European times (but beware this isn’t strict). Here …

Total answers: 6

How to specify date format when using pandas.to_csv?

How to specify date format when using pandas.to_csv? Question: The default output format of to_csv() is: 12/14/2012 12:00:00 AM I cannot figure out how to output only the date part with specific format: 20121214 or date and time in two separate columns in the csv file: 20121214, 084530 The documentation is too brief to give …

Total answers: 4

Why is datetime.strptime not working in this simple example?

Why does trying to use `datetime.strptime` result in " 'module' object has no attribute 'strptime'"? Question: I’m using strptime to convert a date string into a datetime. According to the linked page, formatting like this should work: >>> # Using datetime.strptime() >>> dt = datetime.strptime(“21/11/06 16:30”, “%d/%m/%y %H:%M”) My code is: import datetime dtDate = …

Total answers: 6

Python datetime to string without microsecond component

Python datetime to string without microsecond component Question: I’m adding UTC time strings to Bitbucket API responses that currently only contain Amsterdam (!) time strings. For consistency with the UTC time strings returned elsewhere, the desired format is 2011-11-03 11:07:04 (followed by +00:00, but that’s not germane). What’s the best way to create such a …

Total answers: 16

Creating graph with date and time in axis labels with matplotlib

Creating graph with date and time in ticklabels with matplotlib Question: I have my data in an array of the following structure, [[1293606162197, 0, 0], [1293605477994, 63, 0], [1293605478057, 0, 0], [1293605478072, 2735, 1249], [1293606162213, 0, 0], [1293606162229, 0, 0]] The first column is epoch time (in ms), second is y1 and third is y2. …

Total answers: 2