คำอธิบาย
ใช้ property DateTimeIndex.second ดึงค่าวินาที (0-59) ของแต่ละ timestamp
ตัวอย่างโค้ด
import pandas as pd
datetimeindex = pd.date_range('2021-10-20 02:30:50', periods=6, tz='Australia/Sydney', freq='S')
print("DateTimeIndex...\n", datetimeindex)
print("DateTimeIndex frequency...\n", datetimeindex.freq)
print("\nGetting the seconds..\n", datetimeindex.second)
ผลลัพธ์
DateTimeIndex...
DatetimeIndex(['2021-10-20 02:30:50+11:00', '2021-10-20 02:30:51+11:00',
'2021-10-20 02:30:52+11:00', '2021-10-20 02:30:53+11:00',
'2021-10-20 02:30:54+11:00', '2021-10-20 02:30:55+11:00'],
dtype='datetime64[ns, Australia/Sydney]', freq='S')
Getting the seconds..
Int64Index([50, 51, 52, 53, 54, 55], dtype='int64')