To obtain the number of days in a month of a Period
object, we use the daysinmonth
attribute.
The daysinmonth
attribute takes the syntax below:
Period.daysinmonth
Since it is an attribute, daysinmonth
takes no parameter value.
daysinmonth
returns an int
representing the number of days in a given month of a Period
object.
# A code to illustrate the daysinmonth attribute# importing the pandas libraryimport pandas as pd# creating a Period objecta = pd.Period('2022-5-2 8:00', 'H')# obtaining the number of days in the monthb = a.daysinmonth# printing the valueprint("There are", b, "days in the given month")
Period
object, a
.Period
object using the daysinmonth
attribute. We assign the result to a variable, b
.b
to the console.