bach.SeriesTimestamp.dt
property dt
: bach.series.series_datetime.DateTimeOperation
Get access to date operations.
class DateTimeOperation
(series)date_trunc
(date_part)Truncates date value based on a specified date part. The value is always rounded to the beginning of date_part.
This operation can be applied only on SeriesDate or SeriesTimestamp.
Parameters
date_part
– Allowed values are ‘second’, ‘minute’,
‘hour’, ‘day’, ‘week’, ‘month’, ‘quarter’, and ‘year’.
# return the date corresponding to the Monday of that week
df['week'] = df.some_date_or_timestamp_series.dt.date_trunc('week')
# return the first day of the quarter
df['quarter'] = df.some_date_or_timestamp_series.dt.date_trunc('quarter')
Returns
the truncated timestamp value with a granularity of date_part.
strftime
(format_str)Allow formatting of this Series (to a string type).
Parameters
format_str
– The format to apply to the date/time column. See Supported Format Codes below for
more information on what is supported.
Returns
a SeriesString containing the formatted date.
Supported Format Codes
A subset of the C standard format codes is supported. See the python documentation for the code semantics: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes
The subset of codes that are supported across all databases is:
%A
, %B
, %F
, %H
, %I
, %M
, %R
, %S
, %T
, %Y
, %a
, %b
, %d
, %j
, %m
, %y
,
%%
Additionally one specific combination is supported: %S.%f
Example
df['year'] = df.some_date_series.dt.strftime('%Y') # return year
df['date'] = df.some_date_series.dt.strftime('%Y%m%d') # return date