Pandas PeriodIndex property days_in_month in Python
The Pandas PeriodIndex property days_in_month used to retrieve the days in month. It returns an Index that includes number that represents the days in the month.
Syntax
 1 PeriodIndex.days_in_month
days_in_month property
 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)
In the above example, a PeriodIndex object is created by passing an array of dates and freq is D. A days_in_month property is access that returns array that includes days in month for each elements of PeriodIndex. The result is assign to the variable that will be printed on console.
Output
 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')

Example 2

Example 2
 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)
In the above example, a PeriodIndex object is created using date_range() with time and freq is D. A days_in_month property is access that returns array that includes days in month for each elements of PeriodIndex. The result is assign to the variable that will be print.
Output
 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')
Privacy Policy
Terms of Service
Disclaimer
Contact us
About us