PeriodIndex를 생성하려면 pandas.PeriodIndex()를 사용하세요. 방법. PeriodIndex.daysinmonth를 사용하여 월의 날짜를 가져옵니다. 재산
먼저 필요한 라이브러리를 가져옵니다 -
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 specific month from the PeriodIndex...\n", periodIndex.daysinmonth) 예시
다음은 코드입니다 -
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 the month number i.e. 1 = January, 2 = February ... 12 = December
print("\nMonth number...\n", periodIndex.month)
# Display days in the specific month from the PeriodIndex object
print("\nDays of the specific month from the PeriodIndex...\n", periodIndex.daysinmonth) 출력
이것은 다음 코드를 생성합니다 -
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> Month number... Int64Index([7, 10, 11, 9, 3, 6], dtype='int64') Days of the specific month from the PeriodIndex... Int64Index([31, 31, 30, 30, 31, 30], dtype='int64')