কম্পিউটার

Python Pandas - একটি PeriodIndex তৈরি করুন এবং মাসের দিন পান


একটি PeriodIndex তৈরি করতে, pandas.PeriodIndex() ব্যবহার করুন পদ্ধতি PeriodIndex.daysinmonth ব্যবহার করে মাসের দিনগুলি পান৷ সম্পত্তি

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

import pandas as pd

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

ব্যবহার করে ফ্রিকোয়েন্সি সেট করেছি
periodIndex = pd.PeriodIndex(['2018-07-25', '2019-10-30', '2020-11-20',
'2021-09-15', '2022-03-12', '2023-06-18'], freq="D")

ডিসপ্লে PeriodIndex অবজেক্ট −

print("PeriodIndex...\n", periodIndex)

PeriodIndex অবজেক্ট -

থেকে নির্দিষ্ট মাসে দিনগুলি প্রদর্শন করুন
print("\nDays of the specific month from the PeriodIndex...\n", periodIndex.daysinmonth)

উদাহরণ

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

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(['2018-07-25', '2019-10-30', '2020-11-20',
'2021-09-15', '2022-03-12', '2023-06-18'], freq="D")

# Display PeriodIndex object
print("PeriodIndex...\n", periodIndex)

# Display PeriodIndex frequency
print("\nPeriodIndex frequency...\n", periodIndex.freq)

# Display the month number i.e. 1 = January, 2 = February ... 12 = December
print("\nMonth number...\n", periodIndex.month)

# Display days in the specific month from the PeriodIndex object
print("\nDays of the specific month from the PeriodIndex...\n", periodIndex.daysinmonth)

আউটপুট

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

PeriodIndex...
PeriodIndex(['2018-07-25', '2019-10-30', '2020-11-20', '2021-09-15', '2022-03-12', '2023-06-18'],
dtype='period[D]')

PeriodIndex frequency...
<Day>

Month number...
Int64Index([7, 10, 11, 9, 3, 6], dtype='int64')

Days of the specific month from the PeriodIndex...
Int64Index([31, 31, 30, 30, 31, 30], dtype='int64')

  1. Python Pandas - পিরিয়ড অবজেক্ট থেকে বছরের দিন পান

  2. Python Pandas - পিরিয়ড যে সপ্তাহে আছে সেই সপ্তাহের দিন পান

  3. Python Pandas - মাসের যে দিনটি একটি পিরিয়ড পড়ে সেই দিনটি পান৷

  4. কিভাবে পাইথনে এক মাসের শেষ দিন পাবেন?