কম্পিউটার

Python Pandas - DateTimeIndex-এ তারিখটি লিপ ইয়ারের অন্তর্গত কিনা তা নির্দেশ করুন


DateTimeIndex-এ তারিখটি একটি লিপ ইয়ারের অন্তর্গত কিনা তা পরীক্ষা করতে, DateTimeIndex.is_leap_year ব্যবহার করুন সম্পত্তি

প্রথমে, প্রয়োজনীয় লাইব্রেরিগুলি আমদানি করুন -

import pandas as pd

পিরিয়ড 6 এবং Y অর্থাৎ বছর −

হিসাবে ফ্রিকোয়েন্সি সহ একটি তারিখ সময় সূচক তৈরি করুন
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]

  1. Python Pandas - DateTimeIndex-এ তারিখটি মাসের শেষ দিন কিনা তা নির্দেশ করুন

  2. Python Pandas - DateTimeIndex-এ তারিখটি মাসের প্রথম দিন কিনা তা নির্দেশ করুন

  3. Python Pandas - DateTimeIndex থেকে ফ্রিকোয়েন্সি বের করুন

  4. Python Pandas - পিরিয়ড অবজেক্ট থেকে বছরটি একটি লিপ ইয়ার কিনা তা পরীক্ষা করুন