কম্পিউটার

Python Pandas - PeriodIndex বস্তু থেকে বছর পান


PeriodIndex বস্তু থেকে বছর পেতে, PeriodIndex.year ব্যবহার করুন সম্পত্তি।

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

import pandas as pd

একটি PeriodIndex অবজেক্ট তৈরি করুন। আমরা "freq" প্যারামিটার −

ব্যবহার করে ফ্রিকোয়েন্সি সেট করেছি
periodIndex = pd.PeriodIndex(['2021-09-25 07:30:35', '2019-10-30 04:15:45',
'2021-07-15 02:55:15', '2022-06-25 09:40:55'], freq="T")

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

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

ডিসপ্লে পিরিয়ড ইনডেক্স ফ্রিকোয়েন্সি −

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

PeriodIndex অবজেক্ট −

থেকে প্রদর্শনের বছর
print("\nThe year from the PeriodIndex object...\n", periodIndex.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:30:35', '2019-10-30 04:15:45',
'2021-07-15 02:55:15', '2022-06-25 09:40: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)

# Display year from the PeriodIndex object
print("\nThe year from the PeriodIndex object...\n", periodIndex.year)

আউটপুট

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

PeriodIndex...
PeriodIndex(['2021-09-25 07:30', '2019-10-30 04:15', '2021-07-15 02:55', '2022-06-25 09:40'],
dtype='period[T]')

PeriodIndex frequency object...
<Minute>

PeriodIndex frequency object as a string...
T

The year from the PeriodIndex object...
Int64Index([2021, 2019, 2021, 2022], dtype='int64')

  1. Python Pandas - স্ট্রিং ইনপুট ব্যবহার করে Timedelta অবজেক্ট থেকে সেকেন্ড পান

  2. Python Pandas - পূর্ণসংখ্যা ইনপুট ব্যবহার করে Timedelta অবজেক্ট থেকে সেকেন্ড পান

  3. Python - পান্ডাসে টাইমস্ট্যাম্প অবজেক্ট থেকে সপ্তাহের দিন পান

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