Series.dt可用于以datetimelike的形式访问序列的值并返回几个属性。 Pandas  Series.dt.is_year_end属性返回一个布尔值,指示日期是否为一年的最后一天。
用法: Series.dt.is_year_end
参数:没有
返回:numpy数组
范例1:采用Series.dt.is_year_end属性以检查给定系列对象的基础数据中的日期是否为一年的最后一天。
# importing pandas as pd 
import pandas as pd 
  
# Creating the Series 
sr = pd.Series(['2012-12-31', '2019-1-1 12:30', '2008-02-2 10:30', 
               '2010-1-1 09:25', '2019-12-31 00:00']) 
  
# Creating the index 
idx = ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5'] 
  
# set the index 
sr.index = idx 
  
# Convert the underlying data to datetime  
sr = pd.to_datetime(sr) 
  
# Print the series 
print(sr)输出:

现在我们将使用Series.dt.is_year_end属性以检查给定系列对象中的日期是否为一年的最后一天。
# check if dates are the 
# last day of a year 
result = sr.dt.is_year_end 
  
# print the result 
print(result)输出:

正如我们在输出中看到的,Series.dt.is_year_end属性已成功访问并返回布尔值,该布尔值指示日期是否为一年的最后一天。
范例2:采用Series.dt.is_year_end属性以检查给定系列对象的基础数据中的日期是否为一年的最后一天。
# importing pandas as pd 
import pandas as pd 
  
# Creating the Series 
sr = pd.Series(pd.date_range('2012-12-31 00:00', periods = 5, freq = 'D')) 
  
# Creating the index 
idx = ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5'] 
  
# set the index 
sr.index = idx 
  
# Print the series 
print(sr)输出:

现在我们将使用Series.dt.is_year_end属性以检查给定系列对象中的日期是否为一年的最后一天。
# check if dates are the 
# last day of a year 
result = sr.dt.is_year_end 
  
# print the result 
print(result)输出:

正如我们在输出中看到的,Series.dt.is_year_end属性已成功访问并返回布尔值,该布尔值指示日期是否为一年的最后一天。
相关用法
- Python pandas.map()用法及代码示例
 - Python Pandas Series.str.len()用法及代码示例
 - Python Pandas.factorize()用法及代码示例
 - Python Pandas TimedeltaIndex.name用法及代码示例
 - Python Pandas dataframe.ne()用法及代码示例
 - Python Pandas Series.between()用法及代码示例
 - Python Pandas DataFrame.where()用法及代码示例
 - Python Pandas Series.add()用法及代码示例
 - Python Pandas.pivot_table()用法及代码示例
 - Python Pandas Series.mod()用法及代码示例
 - Python Pandas Dataframe.at[ ]用法及代码示例
 - Python Pandas Dataframe.iat[ ]用法及代码示例
 - Python Pandas.pivot()用法及代码示例
 - Python Pandas dataframe.mul()用法及代码示例
 - Python Pandas.melt()用法及代码示例
 
注:本文由纯净天空筛选整理自Shubham__Ranjan大神的英文原创作品 Python | Pandas Series.dt.is_year_end。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
