নির্দিষ্ট ফ্রিকোয়েন্সিতে PeriodArray রূপান্তর করতে, periodIndex.asfreq() ব্যবহার করুন পদ্ধতি।
প্রথমে, প্রয়োজনীয় লাইব্রেরিগুলি আমদানি করুন -
import pandas as pd
একটি PeriodIndex অবজেক্ট তৈরি করুন -
periodIndex = pd.PeriodIndex(['2021-09-25 07:30:35', '2019-10-30 04:15:45', '2020-07-15 02:55:15', '2022-06-25 09:40:55'], freq="Y")
ডিসপ্লে PeriodIndex অবজেক্ট −
print("PeriodIndex...\n", periodIndex)
নির্দিষ্ট ফ্রিকোয়েন্সিতে রূপান্তর করুন। আমরা asfreq() −
এর প্যারামিটার হিসাবে ফ্রিকোয়েন্সি সেট করেছিprint("\nConvert..\n", periodIndex.asfreq('M')) উদাহরণ
নিম্নলিখিত কোড -
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',
'2020-07-15 02:55:15', '2022-06-25 09:40:55'], freq="Y")
# 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)
# Convert to the specified frequency
# We have set the frequency as the parameter of the asfreq()
print("\nConvert..\n", periodIndex.asfreq('M')) আউটপুট
এটি নিম্নলিখিত কোড তৈরি করবে -
PeriodIndex... PeriodIndex(['2021', '2019', '2020', '2022'], dtype='period[A-DEC]') PeriodIndex frequency object... <YearEnd: month=12> PeriodIndex frequency object as a string... A-DEC Convert.. PeriodIndex(['2021-12', '2019-12', '2020-12', '2022-12'], dtype='period[M]')