특정 시계열 빈도로 DateTimeIndex에서 연도를 추출하려면 DateTimeIndex.day를 사용하세요. 재산.
먼저 필요한 라이브러리를 가져옵니다 -
import pandas as pd
기간이 6이고 빈도가 D 즉 일인 DatetimeIndex. 시간대는 호주/시드니입니다 -
datetimeindex = pd.date_range('2021-10-20 02:35:55', periods=6, tz='Australia/Sydney',freq='D') DateTimeIndex 표시 -
print("DateTimeIndex...\n", datetimeindex) 하루를 보내세요 -
print("\nGetting the day..\n",datetimeindex.day)
예
다음은 코드입니다 -
import pandas as pd
# DatetimeIndex with period 6 and frequency as D i.e. day
# timezone is Australia/Sydney
datetimeindex = pd.date_range('2021-10-20 02:35:55', periods=6, tz='Australia/Sydney',freq='D')
# display DateTimeIndex
print("DateTimeIndex...\n", datetimeindex)
# display DateTimeIndex frequency
print("DateTimeIndex frequency...\n", datetimeindex.freq)
# get the day
print("\nGetting the day..\n",datetimeindex.day) 출력
이것은 다음과 같은 출력을 생성합니다 -
DateTimeIndex...
DatetimeIndex(['2021-10-20 02:35:55+11:00', '2021-10-21 02:35:55+11:00',
'2021-10-22 02:35:55+11:00', '2021-10-23 02:35:55+11:00',
'2021-10-24 02:35:55+11:00', '2021-10-25 02:35:55+11:00'],
dtype='datetime64[ns, Australia/Sydney]', freq='D')
DateTimeIndex frequency...
<Day>
Getting the day..
Int64Index([20, 21, 22, 23, 24, 25], dtype='int64')