
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python Pandas - Format the Period object and display the Time with 24-Hour format
To format the Period object, use the period.strftime() method and to display the time with 24-Hour format, set the parameter as %H.
At first, import the required libraries −
import pandas as pd
The pandas.Period represents a period of time. Creating a Period object
period = pd.Period(freq="S", year = 2021, month = 9, day = 18, hour = 17, minute = 20, second = 45)
Display the Period object
print("Period...\n", period)
Display the result. Here, Time is displayed with 24-Hour format i.e. [00,23]
print("\nString representation (24-Hour format)...\n", period.strftime('%H'))
Example
Following is the code
import pandas as pd # The pandas.Period represents a period of time # Creating a Period object period = pd.Period(freq="S", year = 2021, month = 9, day = 18, hour = 17, minute = 20, second = 45) # display the Period object print("Period...\n", period) # display the result # Here, Time is displayed with 24-Hour format i.e. [00,23] print("\nString representation (24-Hour format)...\n", period.strftime('%H'))
Output
This will produce the following code
Period... 2021-09-18 17:20:45 String representation (24-Hour format)... 17
- Related Articles
- Python Pandas - Format the Period object and display Quarter
- Python Pandas - Format the Period object and display the Year without century
- Java Program to display time in 24-hour format
- Converting 12 hour format time to 24 hour format in JavaScript
- Python Pandas - Display the start time of the custom business hour in 24h format from the BusinessHour offset object
- Python Pandas - Display the end time of the custom business hour in 24h format from the BusinessHour offset object
- Python Pandas - Display the start time of the custom business hour in 24h format from the CustomBusinessHour offset object
- Python Pandas - Display the end time of the custom business hour in 24h format from the CustomBusinessHour offset object
- Python Pandas - Format and return the string representation of the Period object
- Python program to convert time from 12 hour to 24 hour format
- C++ program to convert time from 12 hour to 24 hour format
- C# program to convert time from 12 hour to 24 hour format
- Format hour in k (1-24) format in Java
- Format hour in kk (01-24) format in Java
- Java Program to display Time in 12-hour format

Advertisements