目录
1211、pandas.tseries.offsets.SemiMonthEnd.is_year_start方法
1212、pandas.tseries.offsets.SemiMonthEnd.is_year_end方法
1213、pandas.tseries.offsets.SemiMonthBegin.freqstr属性
1214、pandas.tseries.offsets.SemiMonthBegin.name属性
1215、pandas.tseries.offsets.SemiMonthBegin.rule_code属性



一、用法精讲
1211、pandas.tseries.offsets.SemiMonthEnd.is_year_start方法
1211-1、语法
# 1211、pandas.tseries.offsets.SemiMonthEnd.is_year_start方法
pandas.tseries.offsets.SemiMonthEnd.is_year_start(ts)
Return boolean whether a timestamp occurs on the year start.
1211-2、参数
1211-2-1、ts(必需):一个Timestamp或datetime-like对象,表示要检查的日期时间。
1211-3、功能
用于确定给定的日期时间ts是否为该年的开始日期。
1211-4、返回值
返回一个布尔值,若ts是年份的开始日期,则返回True;反之,则返回False。
1211-5、说明
无
1211-6、用法
1211-6-1、数据准备
无
1211-6-2、代码示例
# 1211、pandas.tseries.offsets.SemiMonthEnd.is_year_start方法
import pandas as pd
# 创建SemiMonthEnd偏移量
semi_month_end = pd.tseries.offsets.SemiMonthEnd()
# 创建测试日期
date_1 = pd.Timestamp('2024-01-01') # 年开始
date_2 = pd.Timestamp('2024-12-31') # 年结束
date_3 = pd.Timestamp('2024-06-15') # 不在年开始
date_4 = pd.Timestamp('2023-01-01') # 去年年开始
# 检查日期是否为年开始
print(semi_month_end.is_year_start(date_1))
print(semi_month_end.is_year_start(date_2))
print(semi_month_end.is_year_start(date_3))
print(semi_month_end.is_year_start(date_4))
1211-6-3、结果输出
# 1211、pandas.tseries.offsets.SemiMonthEnd.is_year_start方法
# True
# False
# False
# True
1212、pandas.tseries.offsets.SemiMonthEnd.is_year_end方法
1212-1、语法
# 1212、pandas.tseries.offsets.SemiMonthEnd.is_year_end方法
pandas.tseries.offsets.SemiMonthEnd.is_year_end(ts)
Return boolean whether a timestamp occurs on the year end.
1212-2、参数
1212-2-1、ts(必需):一个Timestamp或datetime-like对象,表示要检查的日期时间。
1212-3、功能
用于判断给定的日期时间ts是否为该年的结束日期。
1212-4、返回值
返回一个布尔值,若ts是年份的结束日期,则返回True;反之,则返回False。
1212-5、说明
无
1212-6、用法
1212-6-1、数据准备
无
1212-6-2、代码示例
# 1212、pandas.tseries.offsets.SemiMonthEnd.is_year_end方法
import pandas as pd
# 创建SemiMonthEnd偏移量
semi_month_end = pd.tseries.offsets.SemiMonthEnd()
# 创建测试日期
date_1 = pd.Timestamp('2024-12-31') # 年结束
date_2 = pd.Timestamp('2024-01-01') # 年开始
date_3 = pd.Timestamp('2024-06-15') # 不在年结束
date_4 = pd.Timestamp('2023-12-31') # 去年年结束
# 检查日期是否为年结束
print(semi_month_end.is_year_end(date_1))
print(semi_month_end.is_year_end(date_2))
print(semi_month_end.is_year_end(date_3))
print(semi_month_end.is_year_end(date_4))
1212-6-3、结果输出
# 1212、pandas.tseries.offsets.SemiMonthEnd.is_year_end方法
# True
# False
# False
# True
1213、pandas.tseries.offsets.SemiMonthBegin.freqstr属性
1213-1、语法
# 1213、pandas.tseries.offsets.SemiMonthBegin.freqstr属性
pandas.tseries.offsets.SemiMonthBegin.freqstr
Return a string representing the frequency.
1213-2、参数
无
1213-3、功能
用于获取SemiMonthBegin偏移量的频率字符串表示。
1213-4、返回值
返回字符串'SMS-15',表示半月开始的频率。
1213-5、说明
无
1213-6、用法
1213-6-1、数据准备
无
1213-6-2、代码示例
# 1213、pandas.tseries.offsets.SemiMonthBegin.freqstr属性
import pandas as pd
# 创建SemiMonthBegin偏移量
semi_month_begin = pd.tseries.offsets.SemiMonthBegin()
# 获取频率字符串
freq_string = semi_month_begin.freqstr
print(freq_string)
1213-6-3、结果输出
# 1213、pandas.tseries.offsets.SemiMonthBegin.freqstr属性
# SMS-15
1214、pandas.tseries.offsets.SemiMonthBegin.name属性
1214-1、语法
# 1214、pandas.tseries.offsets.SemiMonthBegin.name属性
pandas.tseries.offsets.SemiMonthBegin.name
Return a string representing the base frequency.
1214-2、参数
无
1214-3、功能
用于获取该偏移量的名称。
1214-4、返回值
返回一个字符串,用于标识偏移量的类型。
1214-5、说明
无
1214-6、用法
1214-6-1、数据准备
无
1214-6-2、代码示例
# 1214、pandas.tseries.offsets.SemiMonthBegin.name属性
import pandas as pd
# 创建SemiMonthBegin偏移量
semi_month_begin = pd.tseries.offsets.SemiMonthBegin()
# 获取偏移量的名称
offset_name = semi_month_begin.name
print(offset_name)
1214-6-3、结果输出
# 1214、pandas.tseries.offsets.SemiMonthBegin.name属性
# SMS-15
1215、pandas.tseries.offsets.SemiMonthBegin.rule_code属性
1215-1、语法
# 1215、pandas.tseries.offsets.SemiMonthBegin.rule_code属性
pandas.tseries.offsets.SemiMonthBegin.rule_code
1215-2、参数
无
1215-3、功能
用于返回该偏移量的规则代码,该属性通常用来标识偏移量的类型,方便在某些情况下进行识别和处理。
1215-4、返回值
返回一个字符串,表示SemiMonthBegin偏移量的规则代码。
1215-5、说明
无
1215-6、用法
1215-6-1、数据准备
无
1215-6-2、代码示例
# 1215、pandas.tseries.offsets.SemiMonthBegin.rule_code属性
import pandas as pd
# 创建一个SemiMonthBegin偏移量
semi_month_begin = pd.tseries.offsets.SemiMonthBegin()
# 获取规则代码
rule_code = semi_month_begin.rule_code
print(rule_code)
1215-6-3、结果输出
# 1215、pandas.tseries.offsets.SemiMonthBegin.rule_code属性
# SMS-15
4118





