The Pandas Period property days_in_month used to retrieve the number of days for the month in which a specified period belongs. It returns an integer that represents the days in the month.
1 import pandas as pd
2
3 period = pd.Period('2022-05-25', freq = 'H')
4 print('The original period object :')
5 print(period)
6
7 res = period.days_in_month
8 print('The days in month for the specified Period :')
9 print(res)
10
11 period1 = pd.Period('2022-09-22', freq = 'D')
12 print('The original period object :')
13 print(period1)
14 res1 = period1.days_in_month
15 print('The days in month for the specified Period :')
16 print(res1)
17
18 period2 = pd.Period('2022-01-12', freq = 'D')
19 print('The original period object :')
20 print(period2)
21 res2 = period2.days_in_month
22 print('The days in month for the specified Period :')
23 print(res2)
In the above example, a Period object is created by passing a date as string and frequency. A days_in_month property is access that returns integer that represents the day in month in which a specified Period belongs. The result is assign to the variable that will b printed on console.
1 The original period object :
2 2022-05-25 00:00
3 The days in month for the specified Period :
4 31
5
6 The original period object :
7 2022-09-22
8 The days in month for the specified Period :
9 30
10
11 The original period object :
12 2022-01-12
13 The days in month for the specified Period :
14 31
Period with individual components
Period with individual components
1 import pandas as pd
2
3
4 period = pd.Period(year = 2022, month = 5, day = 14, hour = 12, freq = 'h')
5 print('The period object with components :')
6 print(period)
7
8 res1 = period.days_in_month
9 print('The days in month for the specified Period :')
10 print(res1)
In the above example, a Period object is created by passing an individual components. A days_in_month property is access that returns integer that represents the day in month in which a specified Period belongs. The result is assign to the variable that will b print.
1 The period object with components :
2 2022-05-14 12:00
3
4 The days in month for the specified Period :
5 31
Period with ordinal
1 import pandas as pd
2
3
4 period2 = pd.Period(ordinal = 459036, freq = 'h')
5 print('The period object with ordinal :')
6 print(period2)
7
8 res2 = period2.days_in_month
9 print('The days in month for the specified Period :')
10 print(res2)
In the above example, a Period object is created by passing an ordinal value as parameters. A days_in_month property is access that returns integer that represents the day in month in which a specified Period belongs. The result is assign to the variable that will b print.
1 The period object with ordinal :
2 2022-05-14 12:00
3
4 The days in month for the specified Period :
5 31
Related options for your search