1 PeriodIndex.days_in_month
1 import pandas as pd
2
3 pIndex = pd.PeriodIndex(['2023-07-25', '2023-8-30', '2023-9-20'], freq = 'D')
4
5 print('The original PeriodIndex object :')
6 print(pIndex)
7
8 res = pIndex.days_in_month
9 print('The days in month for each elements of PeriodIndex :')
10 print(res)
1 The original PeriodIndex object :
2 PeriodIndex(['2023-07-25', '2023-08-30', '2023-09-20'], dtype='period[D]')
3
4 The days in month for each elements of PeriodIndex :
5 Index([31, 31, 30], dtype='int64')
1 import pandas as pd
2
3 dIndex = pd.date_range('2022-01-01 12:30:32',
4 periods = 3, freq = 'D')
5 pIndex = pd.PeriodIndex(dIndex)
6
7 print('The original PeriodIndex object :')
8 print(pIndex)
9
10 res = pIndex.days_in_month
11 print('The days in month for each elements of PeriodIndex :')
12 print(res)
1 The original PeriodIndex object :
2 PeriodIndex(['2022-01-01', '2022-01-02', '2022-01-03'], dtype='period[D]')
3
4 The days in month for each elements of PeriodIndex :
5 Index([31, 31, 31], dtype='int64')