কম্পিউটার

Python Pandas - পিরিয়ড ইনডেক্স অবজেক্টের তারিখটি লিপ ইয়ারের অন্তর্গত কিনা তা নির্দেশ করুন


PeriodIndex বস্তুর তারিখটি লিপ ইয়ারের অন্তর্গত কিনা তা নির্দেশ করতে, periodIndex.is_leap_year ব্যবহার করুন সম্পত্তি।

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

import pandas as pd

একটি PeriodIndex অবজেক্ট তৈরি করুন -

periodIndex = pd.PeriodIndex(['2021-09-25 07:50:35', '2019-10-30 04:35:45',
'2016-07-15 02:25:15', '2020-06-25 09:20:55'], freq="T")

ডিসপ্লে PeriodIndex অবজেক্ট −

print("PeriodIndex...\n", periodIndex)

তারিখটি একটি লিপ ইয়ার কিনা তা পরীক্ষা করুন −

print("\nWhether the date is a leap year?\n", periodIndex.is_leap_year)

উদাহরণ

নিম্নলিখিত কোড -

import pandas as pd

# Create a PeriodIndex object
# PeriodIndex is an immutable ndarray holding ordinal values indicating regular periods in time
# We have set the frequency using the "freq" parameter
periodIndex = pd.PeriodIndex(['2021-09-25 07:50:35', '2019-10-30 04:35:45',
'2016-07-15 02:25:15', '2020-06-25 09:20:55'], freq="T")

# Display PeriodIndex object
print("PeriodIndex...\n", periodIndex)

# Display PeriodIndex frequency
print("\nPeriodIndex frequency object...\n", periodIndex.freq)

# Display PeriodIndex frequency as string
print("\nPeriodIndex frequency object as a string...\n", periodIndex.freqstr)

# Check whether the date is a leap year
print("\nWhether the date is a leap year?\n", periodIndex.is_leap_year)

আউটপুট

এটি নিম্নলিখিত কোড তৈরি করবে -

PeriodIndex...
PeriodIndex(['2021-09-25 07:50', '2019-10-30 04:35', '2016-07-15 02:25','2020-06-25 09:20'],
dtype='period[T]')

PeriodIndex frequency object...
<Minute>

PeriodIndex frequency object as a string...
T

Whether the date is a leap year?
[False False True True]

  1. Python Pandas - পিরিয়ড অবজেক্ট থেকে বছরের দিন পান

  2. Python Pandas - Timedelta অবজেক্ট থেকে সেকেন্ড রিটার্ন করুন

  3. Python Pandas - Timedelta অবজেক্ট থেকে ন্যানোসেকেন্ড ফেরত দিন

  4. Python Pandas - টাইমস্ট্যাম্প অবজেক্ট থেকে বর্তমান তারিখ এবং সময় পান