কম্পিউটার

Python Pandas - PeriodIndex অবজেক্ট থেকে সপ্তাহের দিন পান


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

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

import pandas as pd

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

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)

PeriodIndex অবজেক্ট থেকে সপ্তাহের দিন প্রদর্শন করুন। সোমবার=0, মঙ্গলবার=1 ... রবিবার=6 −

সহ সপ্তাহের দিন
print("\nThe day of week from the PeriodIndex object...\n", periodIndex.weekday)

উদাহরণ

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

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 week from the PeriodIndex object
print("\nThe week from the PeriodIndex object...\n", periodIndex.week)

# Display day of the week from the PeriodIndex object
# The day of the week with Monday=0, Tuesday=1 ... Sunday=6
print("\nThe day of week from the PeriodIndex object...\n", periodIndex.weekday)

আউটপুট

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

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 week from the PeriodIndex object...
Int64Index([38, 44, 28, 25], dtype='int64')

The day of week from the PeriodIndex object...
Int64Index([5, 2, 3, 5], dtype='int64')

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

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

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

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