কম্পিউটার টিউটোরিয়াল

পাইথন প্যান্ডাস - DateTimeIndex-এ তারিখ মাসের প্রথম দিন কিনা তা নির্দেশ করুন

পাইথন প্যান্ডাসে DateTimeIndex.is_month_start প্রোপার্টি ব্যবহার করে DateTimeIndex-এ वाली তারিখটি মাসের প্রথম দিন কিনা তা যাচাই করা যায়। এটি একটি বুলিয়ান অ্যারে রিটার্ন করে।

প্রয়োজনীয় লাইব্রেরি ইম্পোর্ট করুন

import pandas as pd

DatetimeIndex তৈরি করুন

৬টি পিরিয়ড এবং ৫ দিনের ফ্রিকোয়েন্সি (freq='5D') সহ একটি DatetimeIndex তৈরি করুন। টাইমজোন Australia/Adelaide।

datetimeindex = pd.date_range('2021-9-21 02:30:50', periods=6, tz='Australia/Adelaide', freq='5D')

DateTimeIndex প্রদর্শন করুন

print("DateTimeIndex...\n", datetimeindex)

মাসের প্রথম দিন কিনা তা চেক করুন

print("\nCheck whether the date in DateTimeIndex is the first day of the month...\n", datetimeindex.is_month_start)

সম্পূর্ণ উদাহরণ

import pandas as pd

# ৬টি পিরিয়ড এবং ৫ দিনের ফ্রিকোয়েন্সি সহ DatetimeIndex
# টাইমজোন: Australia/Adelaide
datetimeindex = pd.date_range('2021-9-21 02:30:50', periods=6, tz='Australia/Adelaide', freq='5D')

# DateTimeIndex প্রদর্শন
print("DateTimeIndex...\n", datetimeindex)

# DateTimeIndex ফ্রিকোয়েন্সি প্রদর্শন
print("DateTimeIndex frequency...\n", datetimeindex.freq)

# মাসের প্রথম দিন কিনা চেক করুন
print("\nCheck whether the date in DateTimeIndex is the first day of the month...\n", datetimeindex.is_month_start)

আউটপুট

DateTimeIndex... DatetimeIndex(['2021-09-21 02:30:50+09:30', '2021-09-26 02:30:50+09:30', '2021-10-01 02:30:50+09:30', '2021-10-06 02:30:50+10:30', '2021-10-11 02:30:50+10:30', '2021-10-16 02:30:50+10:30'], dtype='datetime64[ns, Australia/Adelaide]', freq='5D')
DateTimeIndex frequency... <5 * Days>
Check whether the date in DateTimeIndex is the first day of the month... [False False True False False False]

ব্যাখ্যা: তৃতীয় তারিখ (২০২১-১০-০১) অক্টোবরের প্রথম দিন হওয়ায় True দেখাচ্ছে।

  1. পাইথন প্যান্ডাস - Period অবজেক্টের সপ্তাহের দিন বের করুন

  2. পাইথন প্যান্ডাস - Period অবজেক্ট থেকে মাসের দিন বের করুন

  3. পাইথন প্যান্ডাস - প্রথম ঘটনার বাদে ডুপ্লিকেট ইন্ডেক্স মান নির্দেশ করা

  4. Python ব্যবহার করে একটি নির্দিষ্ট বছরের প্রথম দিন বের করার পদ্ধতি