यह जांचने के लिए कि DateTimeIndex में दिनांक लीप वर्ष से संबंधित है या नहीं, DateTimeIndex.is_leap_year प्रॉपर्टी का उपयोग करें।
आवश्यक लाइब्रेरी आयात करें
import pandas as pd
DatetimeIndex बनाएं
पीरियड 6 और आवृत्ति Y यानी वर्ष के साथ DatetimeIndex बनाएं।
datetimeindex = pd.date_range('2021-12-30 02:30:50', periods=6, tz='Australia/Adelaide', freq='3Y')
DateTimeIndex प्रदर्शित करें
print("DateTimeIndex...\n", datetimeindex)
जांचें कि DateTimeIndex में दिनांक लीप वर्ष है या नहीं
print("\nCheck whether the date in DateTimeIndex belongs to a leap year or not...\n", datetimeindex.is_leap_year)
पूरा उदाहरण
import pandas as pd
# DatetimeIndex with period 6 and frequency as Y i.e. years
# The timezone is Australia/Adelaide
datetimeindex = pd.date_range('2021-12-30 02:30:50', periods=6, tz='Australia/Adelaide', freq='3Y')
# display DateTimeIndex
print("DateTimeIndex...\n", datetimeindex)
# display DateTimeIndex frequency
print("\nDateTimeIndex frequency...\n", datetimeindex.freq)
# Check whether the date in DateTimeIndex is a leap year or not
print("\nCheck whether the date in DateTimeIndex belongs to a leap year or not...\n", datetimeindex.is_leap_year)
आउटपुट
DateTimeIndex... DatetimeIndex(['2021-12-31 02:30:50+10:30', '2024-12-31 02:30:50+10:30', '2027-12-31 02:30:50+10:30', '2030-12-31 02:30:50+10:30', '2033-12-31 02:30:50+10:30', '2036-12-31 02:30:50+10:30'], dtype='datetime64[ns, Australia/Adelaide]', freq='3A-DEC') DateTimeIndex frequency... <3 * YearEnds: month=12> Check whether the date in DateTimeIndex belongs to a leap year or not... [False True False False False True]