Change language

Python | Pandas PeriodIndex.strftime

|

PeriodIndex.strftime() Pandas PeriodIndex.strftime() returns an array of formatted strings specified in date_format which supports the same string format as the python standard library.

Syntax: PeriodIndex.strftime (date_format)

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

Return: ndarray of formatted strings

Example # 1: Use PeriodIndex.strftime () to print the specified PeriodIndex object in the specified date_format.

# import pandas as pd

import pandas as pd

 
 # Create PeriodIndex object

pidx = pd .PeriodIndex (start = ’2004-11-11 02:45:21’ ,

  end = ’2021-5-21 8: 45: 29’ , freq = ’Y’ )

  
# Print PeriodIndex object

print (pidx)

Output:

Now we will use PeriodIndex.strftime () to return each element of the period to pho rmate ("% b.% D,% Y was% A").

# return PeriodIndex in the specified format

pidx.strftime ( ’% b. % d,% Y was a% A’ )

]

Output:

As we can see in the output, PeriodIndex.strftime () returned an Index object containing each element of this PeriodIndex object in the specified format.

Example # 2: Use PeriodIndex.strftime () to print the given PeriodIndex object in the specified date_format format.

# import pandas as pd

import pandas as pd

 
# Create PeriodIndex object

pidx = pd.PeriodIndex (sta rt = ’2016-10-12 11: 12: 02’

end = ’2020-04-12 11: 32: 12’ , freq = ’Q’ )

  
# Print PeriodIndex object

print (pidx )

Output:

Now we will use PeriodIndex.strftime () to return each period item in the format (& # 39;% b-% Y & # 39;).

# return PeriodIndex in the specified format

pidx.strftime ( ’% b-% Y’ )

]

Output:

As we can see in the output, PeriodIndex.strftime () returned an Index object containing each element of this PeriodIndex object in the specified 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

News


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