📜  Python| Pandas Period.daysinmonth

📅  最后修改于: 2022-05-13 01:55:45.214000             🧑  作者: Mango

Python| Pandas Period.daysinmonth

Python是一种用于进行数据分析的出色语言,主要是因为以数据为中心的Python包的奇妙生态系统。 Pandas就是其中之一,它使导入和分析数据变得更加容易。

Pandas Period.daysinmonth属性返回给定 Period 对象中存在的月份中的天数。

示例 #1:使用Period.daysinmonth属性在给定的 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.daysinmonth属性来查找在给定期间对象中表示的月份中存在的天数。

# return the number of days
prd.daysinmonth

输出 :

正如我们在输出中看到的, Period.daysinmonth属性返回 28,表示给定 period 对象中表示的月份有 28 天。

示例 #2:使用Period.daysinmonth属性在给定的 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.daysinmonth属性来查找在给定期间对象中表示的月份中存在的天数。

# return the number of days
prd.daysinmonth

输出 :

正如我们在输出中看到的, Period.daysinmonth属性返回了 31,表示给定 period 对象中表示的月份有 31 天。