কম্পিউটার

Python Pandas - PeriodIndex অবজেক্ট থেকে সময়কালের ঘন্টা পান


PeriodIndex বস্তু থেকে সময়কালের ঘন্টা পেতে, PeriodIndex.hour ব্যবহার করুন সম্পত্তি।

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

import pandas as pd

একটি PeriodIndex অবজেক্ট তৈরি করুন। PeriodIndex হল একটি অপরিবর্তনীয় ndarray যার অর্ডিনাল মান রয়েছে যা নির্দিষ্ট সময়ের মধ্যে নিয়মিত পিরিয়ড নির্দেশ করে। আমরা "freq" প্যারামিটার −

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

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

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

PeriodIndex অবজেক্ট থেকে প্রদর্শনের ঘন্টা −

print("\nThe hour from the PeriodIndex object...\n", periodIndex.hour)

উদাহরণ

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

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',
'2021-07-15 02:25:15', '2022-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)

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

আউটপুট

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

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

PeriodIndex frequency object...
<Minute>

PeriodIndex frequency object as a string...
T

The hour from the PeriodIndex object...
Int64Index([7, 4, 2, 9], dtype='int64')

  1. Python Pandas - প্রদত্ত পিরিয়ড অবজেক্টের ফ্রিকোয়েন্সি পান

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

  3. Python Pandas - Timedelta অবজেক্ট থেকে মোট সেকেন্ড সময় পান

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