PeriodIndex를 생성하려면 pandas.PeriodIndex()를 사용하세요. 방법. PeriodIndex.dayofyear를 사용하여 요일 가져오기 재산.
먼저 필요한 라이브러리를 가져옵니다 -
import pandas as pd
PeriodIndex 개체를 만듭니다. PeriodIndex는 시간의 규칙적인 기간을 나타내는 서수 값을 보유하는 변경할 수 없는 ndarray입니다. "freq" 매개변수를 사용하여 주파수를 설정했습니다 -
periodIndex = pd.PeriodIndex(['2018-07-25', '2019-10-30', '2020-11-20', '2021-09-15', '2022-03-12', '2023-06-18'], freq="D")
PeriodIndex 개체 표시 -
print("PeriodIndex...\n", periodIndex)
PeriodIndex 개체의 날짜 표시 -
print("\nDays of the year from the PeriodIndex...\n", periodIndex.dayofyear) 예시
다음은 코드입니다 -
import pandas as pd
# Create a PeriodIndex object
# PeriodIndex is an immutable ndarray holding ordinal values indicating regular periods in time
# We have set the frequency using the "freq" parameter
periodIndex = pd.PeriodIndex(['2018-07-25', '2019-10-30', '2020-11-20',
'2021-09-15', '2022-03-12', '2023-06-18'], freq="D")
# Display PeriodIndex object
print("PeriodIndex...\n", periodIndex)
# Display PeriodIndex frequency
print("\nPeriodIndex frequency...\n", periodIndex.freq)
# Display day from the PeriodIndex object
print("\nThe number of days from the PeriodIndex...\n", periodIndex.day)
# Display day of the year from the PeriodIndex object
print("\nDays of the year from the PeriodIndex...\n", periodIndex.dayofyear) 출력
이것은 다음 코드를 생성합니다 -
PeriodIndex... PeriodIndex(['2018-07-25', '2019-10-30', '2020-11-20', '2021-09-15', '2022-03-12', '2023-06-18'], dtype='period[D]') PeriodIndex frequency... <Day> The number of days from the PeriodIndex... Int64Index([25, 30, 20, 15, 12, 18], dtype='int64') Days of the year from the PeriodIndex... Int64Index([206, 303, 325, 258, 71, 169], dtype='int64')