Python Pandas Timestamp.is_year_end
Python是一种进行数据分析的伟大语言,主要是因为以数据为中心的Python包的奇妙生态系统。Pandas就是这些包中的一个,它使导入和分析数据变得更加容易。
Pandas Timestamp.is_year_end属性返回一个布尔值。如果给定的Timestamp对象中的日期是年末,它返回True,否则返回False。
语法 :
Timestamp.is_year_end
参数:无
返回 : 布尔值
例子#1:使用Timestamp.is_year_end属性来检查给定的Timestamp对象中的日期是否是年末。
# importing pandas as pd
import pandas as pd
# Create the Timestamp object
ts = pd.Timestamp(2016, 12, 31, 12)
# Print the Timestamp object
print(ts)
输出 :

现在我们将使用Timestamp.is_year_end属性来检查ts对象中的日期是否是年末。
# check if the date is the end of the year
ts.is_year_end
输出 :

正如我们在输出中看到的,Timestamp.is_year_end属性返回了True,表明给定的Timestamp对象中的日期是一年的结束。
例子2:使用Timestamp.is_year_end属性来检查给定的Timestamp对象中的日期是否是年末。
# importing pandas as pd
import pandas as pd
# Create the Timestamp object
ts = pd.Timestamp(year = 2009, month = 5, day = 31,
hour = 4, tz = 'Europe/Berlin')
# Print the Timestamp object
print(ts)
输出 :

现在我们将使用Timestamp.is_year_end属性来检查ts对象中的日期是否是年末。
# check if the date is the end of the year
ts.is_year_end
输出 :

正如我们在输出中看到的,Timestamp.is_year_end属性返回了False,表明给定的Timestamp对象中的日期不是一年的结束。
极客教程