Change language

Python | Pandas DatetimeIndex.strftime ()

|

DatetimeIndex.strftime() Pandas DatetimeIndex.strftime() is converted to an index using the specified date_format. The function returns the index of the formatted strings specified by the date_format parameter, which supports the same string format as the python standard library.

Syntax: DatetimeIndex.strftime (date_format)

Parameters:
date_format: Date format string (eg “% Y-% m-% d”).

Return: Index of formatted strings

Example # 1: Use DatetimeIndex.strftime () to convert the given DatetimeIndex object to the specified format.

# import pandas as pd

import pandas as pd

 
# Create DatetimeIndex
# Here & # 39; Q & # 39; represents the end-of-quarter frequency

didx = pd .DatetimeIndex (start = ’2000-01-15 08: 00’ , freq = ’Q’ ,

periods = 4 , tz = ’ Asia / Calcutta’ )

 
# Print DatetimeIndex

print (didx)

Output:

Now we want convert the given DatetimeIndex object to (& # 39;% B% d,% Y,% r & # 39;) .

# change the date and time format.

didx.strftime ( ’% B% d,% Y,% r’ )

Output:

As we see in the output, the function changed the format of the DatetimeIndex object to the desired format.

Example # 2: Use DatetimeIndex.strftime () to convert the given DatetimeIndex object to the specified format.

# import pandas as pd

import pandas as pd

 
# Create DatetimeIndex
# Here MS stands for the frequency of the beginning of the month

didx = pd.date_range (pd.Timestamp ( " 2000-01-15 08:00 " ),

periods = 5 , freq = ’MS’ )

  
# Print DatetimeIndex

print (didx)

Output:

Now we want to convert this DatetimeIndex to (& # 39;% B% Y,% r & # 39;) .

Output:

As we can see in the output, the function changed the format of the DatetimeIndex object to the desired format.

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method

# change the date and time format.

didx.strftime ( ’% B% Y,% r’ )