পাইথন প্যান্ডাসে DateTimeIndex.is_month_end প্রোপার্টি ব্যবহার করে DateTimeIndex-এ الموجودة তারিখটি মাসের শেষ দিন কিনা তা সহজেই যাচাই করা যায়। এটি একটি বুলিয়ান অ্যারে রিটার্ন করে।
প্রয়োজনীয় লাইব্রেরি ইম্পোর্ট করুন
import pandas as pd
DatetimeIndex তৈরি করুন
৬টি পিরিয়ড এবং ১৫ দিনের ফ্রিকোয়েন্সি (freq='15D') সহ একটি DatetimeIndex তৈরি করুন। টাইমজোন Australia/Adelaide।
datetimeindex = pd.date_range('2021-9-15 06:40:35', periods=6, tz='Australia/Adelaide', freq='15D')
DateTimeIndex প্রদর্শন করুন
print("DateTimeIndex...\n", datetimeindex)
মাসের শেষ দিন কিনা তা চেক করুন
print("\nCheck whether the date in DateTimeIndex is the last day of the month...\n", datetimeindex.is_month_end)
সম্পূর্ণ উদাহরণ
import pandas as pd
# ৬টি পিরিয়ড এবং ১৫ দিনের ফ্রিকোয়েন্সি সহ DatetimeIndex
# টাইমজোন: Australia/Adelaide
datetimeindex = pd.date_range('2021-9-15 06:40:35', periods=6, tz='Australia/Adelaide', freq='15D')
# DateTimeIndex প্রদর্শন
print("DateTimeIndex...\n", datetimeindex)
# DateTimeIndex ফ্রিকোয়েন্সি প্রদর্শন
print("DateTimeIndex frequency...\n", datetimeindex.freq)
# মাসের শেষ দিন কিনা চেক করুন
print("\nCheck whether the date in DateTimeIndex is the last day of the month...\n", datetimeindex.is_month_end)
আউটপুট
DateTimeIndex... DatetimeIndex(['2021-09-15 06:40:35+09:30', '2021-09-30 06:40:35+09:30', '2021-10-15 06:40:35+10:30', '2021-10-30 06:40:35+10:30', '2021-11-14 06:40:35+10:30', '2021-11-29 06:40:35+10:30'], dtype='datetime64[ns, Australia/Adelaide]', freq='15D') DateTimeIndex frequency... <15 * Days> Check whether the date in DateTimeIndex is the last day of the month... [False True False False False False]
ব্যাখ্যা: দ্বিতীয় তারিখ (২০২১-০৯-৩০) সেপ্টেম্বরের শেষ দিন হওয়ায় True দেখাচ্ছে।