
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Extract Minute from DatetimeIndex in Python Pandas
To extract the minute from the DateTimeIndex with specific time series frequency, use the DateTimeIndex.minute property.
At first, import the required libraries −
import pandas as pd
Create a DatetimeIndex with period 6 and frequency as T i.e. minute. The timezone is Australia/Sydney −
datetimeindex = pd.date_range('2021-10-20 02:30:55', periods=6, tz='Australia/Sydney', freq='T')
Display DateTimeIndex −
print("DateTimeIndex...\n", datetimeindex)
Get the minute −
print("\nGetting the minute..\n",datetimeindex.minute)
Example
Following is the code −
import pandas as pd # DatetimeIndex with period 6 and frequency as T i.e. minute # The timezone is Australia/Sydney datetimeindex = pd.date_range('2021-10-20 02:30:55', periods=6, tz='Australia/Sydney', freq='T') # display DateTimeIndex print("DateTimeIndex...\n", datetimeindex) # display DateTimeIndex frequency print("DateTimeIndex frequency...\n", datetimeindex.freq) # get the minute print("\nGetting the minute..\n",datetimeindex.minute)
Output
This will produce the following code −
DateTimeIndex... DatetimeIndex(['2021-10-20 02:30:55+11:00', '2021-10-20 02:31:55+11:00', '2021-10-20 02:32:55+11:00', '2021-10-20 02:33:55+11:00', '2021-10-20 02:34:55+11:00', '2021-10-20 02:35:55+11:00'], dtype='datetime64[ns, Australia/Sydney]', freq='T') DateTimeIndex frequency... <Minute> Getting the minute.. Int64Index([30, 31, 32, 33, 34, 35], dtype='int64')
Advertisements