Period অবজেক্ট ফরম্যাট করে স্ট্রিং রিপ্রেজেন্টেশন ফেরত দিতে period.strftime() মেথড ব্যবহার করুন। সেটি ফরম্যাট স্পেসিফায়ার আর্গুমেন্ট হিসেবে নেয়, যেমন strftime('%d-%b-%Y')।
প্রয়োজনীয় লাইব্রেরি ইম্পোর্ট করুন
import pandas as pd
Period অবজেক্ট তৈরি করুন
pandas.Period একটি সময়ের পরিধি উপস্থাপন করে।
period = pd.Period(freq="S", year=2021, month=9, day=18, hour=8, minute=20, second=45)
Period অবজেক্ট প্রদর্শন করুন
print("Period...\n", period)
ফরম্যাট করা স্ট্রিং রিপ্রেজেন্টেশন প্রদর্শন করুন
print("\nString representation (format)...\n", period.strftime('%d-%b-%Y'))
সম্পূর্ণ উদাহরণ
import pandas as pd
# Period অবজেক্ট তৈরি করুন
period = pd.Period(freq="S", year=2021, month=9, day=18, hour=8, minute=20, second=45)
# Period অবজেক্ট প্রদর্শন করুন
print("Period...\n", period)
# ফলাফল প্রদর্শন করুন
print("\nString representation (format)...\n", period.strftime('%d-%b-%Y'))
# ভিন্ন ডিরেক্টিভ দিয়ে ফলাফল প্রদর্শন করুন
print("\nString representation (format with different directives)...\n", period.strftime('%b. %d, %Y was a %A'))
আউটপুট
Period... 2021-09-18 08:20:45 String representation (format)... 18-Sep-2021 String representation (format with different directives)... Sep. 18, 2021 was a Saturday