Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

Python Pandas - ดึงนาทีจาก DateTimeIndex ด้วย minute property


คำอธิบาย

ใช้ property DateTimeIndex.minute ดึงค่านาที (0-59) ของแต่ละ timestamp

ตัวอย่างโค้ด

import pandas as pd

datetimeindex = pd.date_range('2021-10-20 02:30:55', periods=6, tz='Australia/Sydney', freq='T')

print("DateTimeIndex...\n", datetimeindex)
print("DateTimeIndex frequency...\n", datetimeindex.freq)
print("\nGetting the minute..\n", datetimeindex.minute)

ผลลัพธ์

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')

Getting the minute..
Int64Index([30, 31, 32, 33, 34, 35], dtype='int64')