Change language

Python | Pandas Period.strftime

|

Period.strftime() Pandas Period.strftime() returns the string representation of the Period depending on the selected format. The format must be a string containing one or more directives. The method recognizes the same directives as time.strftime () of the standard Python distribution, as well as special additional directives% f,% F,% q. (formatting and docs originally from scikits.timeries)

Syntax: Period.strftime ()

Parameters: format

Return: string

Example # 1: Use Period.strftime () to return the value of the specified period in the specified format.

# import pandas as pd

import pandas as pd

 
# Create Period object

prd = pd.Period (freq = ’S’ , year = 2000 , mo nth = 2 , day = 22

  hour = 8 , minute = 21 , second = 24 )

 
# Print Period object

print (prd)

Exit:

Now we will use Period.strftime ( ) to return a specified period in the format ( & # 39;% b.% D,% Y was% A & # 39;).

Note: & # 39;% b & # 39; — this is the name of the month, % d — this is the day of the month, % Y — this is the year, and % A — name of the day of the week.

# return the period in the specified format.

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

Output:

As we can see in the output, Period.strftime () returned the value of the specified period in the specified format.

Example # 2: Use Period.strftime () to return the value of the specified period in the specified format.

# import pandas as pd

import pandas as pd

  
# Create Period object

prd = pd.Period (freq = ’ S’ , year = 2006 , month = 10

hour = 15 , minute = 49 , second = 17 )

 
# Print object

print (prd)

Output:

We will now use Period. strftime () to return the specified period in the format (& # 39;% b-% Y & # 39;).

Note: & # 39 ;% b & # 39; — month name, % Y — year

# return the period in the specified format.

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

Output:

As we can see in the output, Period.strftime () returned the value of the specified period 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