পাইথন পান্ডাসে DateTimeIndex-এর প্রতিটি ডেটা লিপ ইয়ার (leap year) এ পড়ে কিনা চেক করতে DateTimeIndex.is_leap_year প্রপার্টি ব্যবহার করা হয়।
প্রয়োজনীয় লাইব্রেরি ইম্পোর্ট করুন
import pandas as pd
DateTimeIndex তৈরি করুন
৬টি পিরিয়ড, ৩ বছরের ফ্রিকোয়েন্সি, টাইমজোন: Australia/Adelaide
datetimeindex = pd.date_range('2021-12-30 02:30:50', periods=6, tz='Australia/Adelaide', freq='3Y')
DateTimeIndex প্রদর্শন করুন
print("DateTimeIndex...\n", 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 তৈরি
datetimeindex = pd.date_range('2021-12-30 02:30:50', periods=6, tz='Australia/Adelaide', freq='3Y')
# DateTimeIndex প্রদর্শন
print("DateTimeIndex...\n", datetimeindex)
# ফ্রিকোয়েন্সি দেখুন
print("\nDateTimeIndex frequency...\n", datetimeindex.freq)
# লিপ ইয়ার চেক করুন
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]
ব্যাখ্যা
- জেনারেট করা তারিখগুলো (ইয়ার-এন্ড বেসড): ২০২১, ২০২৪, ২০২৭, ২০৩০, ২০৩৩, ২০৩৬
is_leap_yearরিটার্ন করে বুলিয়ান অ্যারে:- ২০২১: False (লিপ ইয়ার নয়)
- ২০২৪: True (লিপ ইয়ার — ৪ দিয়ে বিভাজ্য, ১০০ দিয়ে নয়)
- ২০২৭: False
- ২০৩০: False
- ২০৩৩: False
- ২০৩৬: True (লিপ ইয়ার)
- ফলাফল:
[False, True, False, False, False, True]
লিপ ইয়ার নির্ণয়ের নিয়ম
- বছর ৪ দিয়ে বিভাজ্য হলে লিপ ইয়ার
- অপবাদ: ১০০ দিয়ে বিভাজ্য হলে লিপ ইয়ার নয় (যেমন ১৯০০, ২১০০)
- অপবাদের অপবাদ: ৪০০ দিয়ে বিভাজ্য হলে লিপ ইয়ার (যেমন ২০০০, ২৪০০)
ব্যবহার ক্ষেত্র
- ফিন্যান্সিয়াল ক্যালকুলেশন (ডে কাউন্ট কনভেনশন: Actual/366 vs Actual/365)
- টাইম সিরিজ রিস্যাম্পলিং (ফেব্রুয়ারি ২৯ হ্যান্ডলিং)
- সিজনালিটি অ্যানালাইসিস (লিপ ইয়ার আডজাস্টমেন্ট)
নোট: এটি একটি প্রপার্টি, মেথড নয় — প্যারেনথেসিস লাগে না। Series.dt.is_leap_year ও সিরিজে উপলব্ধ।