Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Python Pandas - Get the minute of the period from the PeriodIndex object
To get the minute of the period from the PeriodIndex object, use the PeriodIndex.minute property. This property extracts the minute component from each period in the index.
What is PeriodIndex?
PeriodIndex is an immutable ndarray holding ordinal values indicating regular periods in time. It's useful for time-based data analysis where you need to work with specific time periods.
Syntax
PeriodIndex.minute
Example
Let's create a PeriodIndex object and extract the minute component ?
import pandas as pd
# Create a PeriodIndex object with minute frequency
periodIndex = pd.PeriodIndex(['2021-09-25 07:30:35', '2019-10-30 04:15:45',
'2021-07-15 02:55:15', '2022-06-25 09:40:55'], freq="T")
# Display PeriodIndex object
print("PeriodIndex...")
print(periodIndex)
# Display PeriodIndex frequency
print("\nPeriodIndex frequency object...")
print(periodIndex.freq)
# Display minute from the PeriodIndex object
print("\nThe minute from the PeriodIndex object...")
print(periodIndex.minute)
PeriodIndex... PeriodIndex(['2021-09-25 07:30', '2019-10-30 04:15', '2021-07-15 02:55', '2022-06-25 09:40'], dtype='period[T]') PeriodIndex frequency object... <Minute> The minute from the PeriodIndex object... Index([30, 15, 55, 40], dtype='int64')
Key Points
The minute property returns an Index containing the minute values (0-59) extracted from each period. The frequency parameter freq="T" indicates minute-level periods.
Conclusion
The PeriodIndex.minute property provides an efficient way to extract minute components from time period data. This is particularly useful for time-based analysis and filtering operations in pandas.
