특정 시계열 빈도로 DateTimeIndex에서 초를 추출하려면 DateTimeIndex.second를 사용하세요. 재산.
먼저 필요한 라이브러리를 가져옵니다 -
import pandas as pd
기간이 6이고 빈도가 S 즉 초인 DatetimeIndex를 만듭니다. 시간대는 호주/시드니입니다 -
datetimeindex = pd.date_range('2021-10-20 02:30:50', periods=6, tz='Australia/Sydney', freq='S')
DateTimeIndex 표시 -
print("DateTimeIndex...\n", datetimeindex) 초 가져오기 -
print("\nGetting the seconds..\n",datetimeindex.second)
예
다음은 코드입니다 -
import pandas as pd
# DatetimeIndex with period 6 and frequency as S i.e. seconds
# The timezone is Australia/Sydney
datetimeindex = pd.date_range('2021-10-20 02:30:50', periods=6, tz='Australia/Sydney', freq='S')
# display DateTimeIndex
print("DateTimeIndex...\n", datetimeindex)
# display DateTimeIndex frequency
print("DateTimeIndex frequency...\n", datetimeindex.freq)
# get the seconds
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') DateTimeIndex frequency... <Second> Getting the seconds.. Int64Index([50, 51, 52, 53, 54, 55], dtype='int64')