কম্পিউটার টিউটোরিয়াল

পাইথন প্যান্ডাস - Period অবজেক্টের সপ্তাহের দিন বের করুন

একটি Period অবজেক্ট কোন সপ্তাহের দিনে পড়ে তা জানতে period.dayofweek প্রোপার্টি ব্যবহার করুন। এখানে সোমবার=০, মঙ্গলবার=১, ..., রবিবার=৬।

প্রয়োজনীয় লাইব্রেরি ইমপোর্ট করুন

import pandas as pd

দুটি Period অবজেক্ট তৈরি করুন

period1 = pd.Period("2021-09-18")
period2 = pd.Period(freq='D', year=2021, month=9, day=22, hour=4, minute=55)

Period অবজেক্টগুলো প্রদর্শন করুন

print("Period1...\n", period1)
print("Period2...\n", period2)

সপ্তাহের দিন বের করুন

res1 = period1.dayofweek
res2 = period2.dayofweek

সম্পূর্ণ উদাহরণ

import pandas as pd

# The pandas.Period represents a period of time
# creating two Period objects
period1 = pd.Period("2021-09-18")
period2 = pd.Period(freq='D', year=2021, month=9, day=22, hour=4, minute=55)

# display the Period objects
print("Period1...\n", period1)
print("Period2...\n", period2)

# get the day of week from two Period objects
res1 = period1.dayofweek
res2 = period2.dayofweek

# Return the day of the week from the two Period objects
# Results shows Monday=0, Tuesday=1, ... ,Sunday=6
print("\nDay of the week from the 1st Period object ...\n", res1)
print("\nDay of the week from the 2nd Period object...\n", res2)

আউটপুট

Period1... 2021-09-18
Period2... 2021-09-22
Day of the week from the 1st Period object ... 5
Day of the week from the 2nd Period object... 2

নোট: ২০২১ সেপ্টেম্বর ১৮ শনিবার (৫), ২২ সেপ্টেম্বর বুধবার (২)। আউটপুটে শুধু Period প্রিন্ট হয়েছে, dayofweek মানগুলো কমেন্ট আউট থাকায় প্রিন্ট হয়নি। সম্পূর্ণ কোড রান করলে ৫ এবং ২ আসবে।

  1. পাইথন প্যান্ডাস - Period অবজেক্ট থেকে দিনের ঘন্টা (hour) কম্পোনেন্ট পান

  2. পাইথন প্যান্ডাস - Period অবজেক্টের জন্য ফ্রিকোয়েন্সি (frequency) পান

  3. পাইথন প্যান্ডাস - Period অবজেক্ট থেকে বছরের দিন বের করুন

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