Python Pandas Timestamp.day_in_month
Python是一种进行数据分析的伟大语言,主要是因为以数据为中心的Python包的奇妙生态系统。Pandas就是这些包中的一个,它使导入和分析数据变得更加容易。
Pandas Timestamp.days_in_month属性返回Timestamp对象中给定日期的月份天数。
语法 :
Timestamp.day_in_month
参数:无
返回:月内天数
例子#1:使用Timestamp.days_in_month属性来找出给定Timestamp对象的天数。
# importing pandas as pd
import pandas as pd
# Create the Timestamp object
ts = pd.Timestamp(2017, 2, 15, 12)
# Print the Timestamp object
print(ts)
输出 :

现在我们将使用Timestamp.days_in_month属性来找出给定Timestamp对象中的天数。
# return the number of days in month
ts.days_in_month
输出 :

正如我们在输出中看到的,Timestamp.days_in_month属性返回了28,表明在给定的Timestamp对象的月份里有28天。
例子#2:使用Timestamp.days_in_month属性来找出给定的Timestamp对象中的天数。
# importing pandas as pd
import pandas as pd
# Create the Timestamp object
ts = pd.Timestamp(year = 2009, month = 10,
day = 21, tz = 'Europe/Berlin')
# Print the Timestamp object
print(ts)
输出 :

现在我们将使用Timestamp.days_in_month属性来找出给定Timestamp对象中的天数。
# return the number of days in month
ts.days_in_month
输出 :

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