Python Pandas Period.dayinmonth
Python是一种进行数据分析的伟大语言,主要是因为以数据为中心的Python包的奇妙生态系统。Pandas就是这些包中的一个,它使导入和分析数据变得更加容易。
Pandas Period.dayinmonth属性返回给定的Period对象中存在的月份的天数。
语法 :
Period.dayinmonth
参数:无
返回:天数
示例#1:使用Period.dayinmonth属性来查找给定的Period对象中存在于该月的天数。
# importing pandas as pd
import pandas as pd
# Create the Period object
prd = pd.Period(freq ='D', year = 2001, month = 2, day = 21)
# Print the Period object
print(prd)
输出 :

现在我们将使用Period.dayinmonth属性来查找在给定的周期对象中所代表的月份中存在的天数。
# return the number of days
prd.daysinmonth
输出 :

正如我们在输出中看到的,Period.daysinmonth属性返回了28,表明给定的period对象中所代表的月份有28天。
示例#2:使用Period.dayinmonth属性来查找在给定的Period对象中,每月存在的天数。
# importing pandas as pd
import pandas as pd
# Create the Period object
prd = pd.Period(freq ='Q', year = 2006, quarter = 1)
# Print the object
print(prd)
输出 :

现在我们将使用Period.dayinmonth属性来查找在给定的周期对象中所代表的月份中存在的天数。
# return the number of days
prd.daysinmonth
输出 :

正如我们在输出中看到的,Period.dayinmonth属性返回了31,表明在给定的period对象中代表的月份有31天。
极客教程