PeriodIndex 개체의 날짜가 윤년에 속하는지 여부를 나타내려면 periodIndex.is_leap_year를 사용하세요. 재산.
먼저 필요한 라이브러리를 가져옵니다 -
import pandas as pd
PeriodIndex 객체 생성 -
periodIndex = pd.PeriodIndex(['2021-09-25 07:50:35', '2019-10-30 04:35:45', '2016-07-15 02:25:15', '2020-06-25 09:20:55'], freq="T")
PeriodIndex 개체 표시 -
print("PeriodIndex...\n", periodIndex)
날짜가 윤년인지 확인 -
print("\nWhether the date is a leap year?\n", periodIndex.is_leap_year)
예시
다음은 코드입니다 -
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(['2021-09-25 07:50:35', '2019-10-30 04:35:45', '2016-07-15 02:25:15', '2020-06-25 09:20:55'], freq="T") # Display PeriodIndex object print("PeriodIndex...\n", periodIndex) # Display PeriodIndex frequency print("\nPeriodIndex frequency object...\n", periodIndex.freq) # Display PeriodIndex frequency as string print("\nPeriodIndex frequency object as a string...\n", periodIndex.freqstr) # Check whether the date is a leap year print("\nWhether the date is a leap year?\n", periodIndex.is_leap_year)
출력
이것은 다음 코드를 생성합니다 -
PeriodIndex... PeriodIndex(['2021-09-25 07:50', '2019-10-30 04:35', '2016-07-15 02:25','2020-06-25 09:20'], dtype='period[T]') PeriodIndex frequency object... <Minute> PeriodIndex frequency object as a string... T Whether the date is a leap year? [False False True True]