pandas.Series.dt.strftime#

Series.dt.strftime(date_format)[source]#

Format the values as strings using the specified date_format.

The date_format supports the same string format as the python standard library. Details of the string format can be found in python string format doc.

Formats supported by the C strftime API but not by the python string format doc (such as “%R”, “%r”) are not officially supported and should be preferably replaced with their supported equivalents (such as “%H:%M”, “%I:%M:%S %p”).

Period values support additional directives, detailed in Period.strftime.

Parameters:
date_formatstr

Date format string (e.g. “%Y-%m-%d”).

Returns:
Series or array

The formatted strings.

See also

to_datetime

Convert the given argument to datetime.

DatetimeIndex.strftime

Format a DatetimeIndex as strings.

Timestamp.strftime

Format a single Timestamp.

Period.strftime

Format a single Period.

Examples

>>> ser = pd.Series(
...     pd.date_range(pd.Timestamp("2018-03-10 09:00"), periods=3, freq="s")
... )
>>> ser.dt.strftime("%B %d, %Y, %r")
0    March 10, 2018, 09:00:00 AM
1    March 10, 2018, 09:00:01 AM
2    March 10, 2018, 09:00:02 AM
dtype: str