w3resource

Pandas Series: dt.strftime() function

Series.dt.strftime() function

The dt.strftime() function is used to convert to Index using specified date_format.
Return an Index of formatted strings specified by date_format, which supports the same string format as the python standard library.

Syntax:

Series.dt.strftime(self, *args, **kwargs)
Pandas Series: dt.strftime() function

Parameter:

Name Description Type / Default Value Required / Optional
date_format Date format string (e.g. "%Y-%m-%d"). str Required

Returns: DatetimeArray, DatetimeIndex or Series
The same type as the original data. Series will have the same name and index. DatetimeIndex will have the same name.

Example:

Python-Pandas Code:

import numpy as np
import pandas as pd
rng = pd.date_range(pd.Timestamp("2019-04-10 09:00"),
                    periods=3, freq='s')
rng.strftime('%B %d, %Y, %r')

Output:

Index(['April 10, 2019, 09:00:00 AM', 'April 10, 2019, 09:00:01 AM',
       'April 10, 2019, 09:00:02 AM'],
      dtype='object')

Previous: Series.dt.normalize() function
Next: Series.dt.round() function



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/pandas/series/series-dt-strftime.php