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

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

প্যান্ডাস Period অবজেক্ট থেকে বছরের দিন (day of the year) জানতে period.dayofyear প্রোপার্টি ব্যবহার করুন। এটি ১ থেকে ৩৬৫ (লিপইয়ারে ৩৬৬) পর্যন্ত মান রিটার্ন করে।

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

import pandas as pd

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

period1 = pd.Period("2020-09-23")
period2 = pd.Period(freq="D", year=2021, month=7, day=16, hour=2, minute=35)

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

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

বছরের দিন বের করুন

res1 = period1.dayofyear
res2 = period2.dayofyear

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

import pandas as pd

# The pandas.Period represents a period of time
# creating two Period objects
period1 = pd.Period("2020-09-23")
period2 = pd.Period(freq="D", year=2021, month=7, day=16, hour=2, minute=35)

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

# get the day of the year from two Period objects
res1 = period1.dayofyear
res2 = period2.dayofyear

# Return the day of the year from the two Period objects
# The return value ranges between 1 to 365 for regular years and 1 to 366 for leap years
print("\nDay of the year from the 1st Period object ...\n", res1)
print("\nDay of the year from the 2nd Period object...\n", res2)

আউটপুট

Period1... 2020-09-23
Period2... 2021-07-16
Day of the year from the 1st Period object ... 267
Day of the year from the 2nd Period object... 197

ব্যাখ্যা: ২০২০ সেপ্টেম্বর ২৩ তারিখটি লিপইয়ার বছরের ২৬৭তম দিন, আর ২০২১ জুলাই ১৬ তারিখটি সাধারণ বছরের ১৯৭তম দিন।

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

  2. পাইথন প্যান্ডাস - Timedelta অবজেক্ট থেকে মোট সেকেন্ড বের করুন

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

  4. পাইথনে বছরের দিন বের করা (Day of the Year in Python)