Python酷库之旅-第三方库Pandas(255)

目录

一、用法精讲

1206、pandas.tseries.offsets.SemiMonthEnd.is_on_offset方法

1206-1、语法

1206-2、参数

1206-3、功能

1206-4、返回值

1206-5、说明

1206-6、用法

1206-6-1、数据准备

1206-6-2、代码示例

1206-6-3、结果输出

1207、pandas.tseries.offsets.SemiMonthEnd.is_month_start方法

1207-1、语法

1207-2、参数

1207-3、功能

1207-4、返回值

1207-5、说明

1207-6、用法

1207-6-1、数据准备

1207-6-2、代码示例

1207-6-3、结果输出

1208、pandas.tseries.offsets.SemiMonthEnd.is_month_end方法

1208-1、语法

1208-2、参数

1208-3、功能

1208-4、返回值

1208-5、说明

1208-6、用法

1208-6-1、数据准备

1208-6-2、代码示例

1208-6-3、结果输出

1209、pandas.tseries.offsets.SemiMonthEnd.is_quarter_start方法

1209-1、语法

1209-2、参数

1209-3、功能

1209-4、返回值

1209-5、说明

1209-6、用法

1209-6-1、数据准备

1209-6-2、代码示例

1209-6-3、结果输出

1210、pandas.tseries.offsets.SemiMonthEnd.is_quarter_end方法

1210-1、语法

1210-2、参数

1210-3、功能

1210-4、返回值

1210-5、说明

1210-6、用法

1210-6-1、数据准备

1210-6-2、代码示例

1210-6-3、结果输出

二、推荐阅读

1、Python筑基之旅

2、Python函数之旅

3、Python算法之旅

4、Python魔法之旅

5、博客个人主页

一、用法精讲

1206、pandas.tseries.offsets.SemiMonthEnd.is_on_offset方法
1206-1、语法
python 复制代码
# 1206、pandas.tseries.offsets.SemiMonthEnd.is_on_offset方法
pandas.tseries.offsets.SemiMonthEnd.is_on_offset(dt)
Return boolean whether a timestamp intersects with this frequency.

Parameters:
dt
datetime.datetime
Timestamp to check intersections with frequency.
1206-2、参数

**1206-2-1、dt(必需):**一个Timestamp或者datetime-like对象,表示要检查的日期时间。

1206-3、功能

用于确定给定的日期时间dt是否落在半月末(即每月的15号和最后一天)上。

1206-4、返回值

返回一个布尔值,若dt是每月的15号或者该月的最后一天,则返回True;反之,则返回False。

1206-5、说明

1206-6、用法
1206-6-1、数据准备
python 复制代码
1206-6-2、代码示例
python 复制代码
# 1206、pandas.tseries.offsets.SemiMonthEnd.is_on_offset方法
import pandas as pd
# 创建一个SemiMonthEnd偏移量
semi_month_end = pd.tseries.offsets.SemiMonthEnd()
# 创建测试日期
date_1 = pd.Timestamp('2024-03-15')
date_2 = pd.Timestamp('2024-03-31')
date_3 = pd.Timestamp('2024-03-10')
# 检查日期是否在半月末
print(semi_month_end.is_on_offset(date_1))  # True,15日是半月末
print(semi_month_end.is_on_offset(date_2))  # True,31日是该月最后一天
print(semi_month_end.is_on_offset(date_3))  # False,10日不是半月末
1206-6-3、结果输出
python 复制代码
# 1206、pandas.tseries.offsets.SemiMonthEnd.is_on_offset方法
# True
# True
# False
1207、pandas.tseries.offsets.SemiMonthEnd.is_month_start方法
1207-1、语法
python 复制代码
# 1207、pandas.tseries.offsets.SemiMonthEnd.is_month_start方法
pandas.tseries.offsets.SemiMonthEnd.is_month_start(ts)
Return boolean whether a timestamp occurs on the month start.
1207-2、参数

**1207-2-1、ts(必需):**一个Timestamp或者datetime-like对象,表示要检查的日期时间。

1207-3、功能

用于确定给定的日期时间ts是否为该月的第一天。

1207-4、返回值

返回一个布尔值,若ts是该月的第一天,则返回True;反之,则返回False。

1207-5、说明

1207-6、用法
1207-6-1、数据准备
python 复制代码
1207-6-2、代码示例
python 复制代码
# 1207、pandas.tseries.offsets.SemiMonthEnd.is_month_start方法
import pandas as pd
# 创建SemiMonthEnd偏移量
semi_month_end = pd.tseries.offsets.SemiMonthEnd()
# 创建测试日期
date_1 = pd.Timestamp('2024-03-01')
date_2 = pd.Timestamp('2024-03-15')
date_3 = pd.Timestamp('2024-04-01')
# 检查日期是否为月初
print(semi_month_end.is_month_start(date_1))  # True,1日是月初
print(semi_month_end.is_month_start(date_2))  # False,15日不是月初
print(semi_month_end.is_month_start(date_3))  # True,1日是月初
1207-6-3、结果输出
python 复制代码
# 1207、pandas.tseries.offsets.SemiMonthEnd.is_month_start方法
# True
# False
# True
1208、pandas.tseries.offsets.SemiMonthEnd.is_month_end方法
1208-1、语法
python 复制代码
# 1208、pandas.tseries.offsets.SemiMonthEnd.is_month_end方法
pandas.tseries.offsets.SemiMonthEnd.is_month_end(ts)
Return boolean whether a timestamp occurs on the month end.
1208-2、参数

**1208-2-1、ts(必需):**一个Timestamp或者datetime-like对象,表示要检查的日期时间。

1208-3、功能

用于确定给定的日期时间ts是否为该月的最后一天。

1208-4、返回值

返回一个布尔值,若ts是该月的最后一天,则返回True;反之,则返回False。

1208-5、说明

1208-6、用法
1208-6-1、数据准备
python 复制代码
1208-6-2、代码示例
python 复制代码
# 1208、pandas.tseries.offsets.SemiMonthEnd.is_month_end方法
import pandas as pd
# 创建SemiMonthEnd偏移量
semi_month_end = pd.tseries.offsets.SemiMonthEnd()
# 创建测试日期
date_1 = pd.Timestamp('2024-03-31')
date_2 = pd.Timestamp('2024-03-15')
date_3 = pd.Timestamp('2024-04-30')
# 检查日期是否为月末
print(semi_month_end.is_month_end(date_1))  # True,31日是月末
print(semi_month_end.is_month_end(date_2))  # False,15日不是月末
print(semi_month_end.is_month_end(date_3))  # True,30日是月末
1208-6-3、结果输出
python 复制代码
# 1208、pandas.tseries.offsets.SemiMonthEnd.is_month_end方法
# True
# False
# True
1209、pandas.tseries.offsets.SemiMonthEnd.is_quarter_start方法
1209-1、语法
python 复制代码
# 1209、pandas.tseries.offsets.SemiMonthEnd.is_quarter_start方法
pandas.tseries.offsets.SemiMonthEnd.is_quarter_start(ts)
Return boolean whether a timestamp occurs on the quarter start.
1209-2、参数

**1209-2-1、ts(必需):**一个Timestamp或者datetime-like对象,表示要检查的日期时间。

1209-3、功能

用于确定给定的日期时间ts是否为该季度的开始日期。

1209-4、返回值

返回一个布尔值,若ts是季度的开始日期,则返回True;反之,则返回False。

1209-5、说明

1209-6、用法
1209-6-1、数据准备
python 复制代码
1209-6-2、代码示例
python 复制代码
# 1209、pandas.tseries.offsets.SemiMonthEnd.is_quarter_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-04-01')  # 第二季度开始
date_3 = pd.Timestamp('2024-03-15')  # 不是季度开始
date_4 = pd.Timestamp('2024-07-01')  # 第三季度开始
date_5 = pd.Timestamp('2024-10-01')  # 第四季度开始
# 检查日期是否为季度开始
print(semi_month_end.is_quarter_start(date_1))
print(semi_month_end.is_quarter_start(date_2))
print(semi_month_end.is_quarter_start(date_3))
print(semi_month_end.is_quarter_start(date_4))
print(semi_month_end.is_quarter_start(date_5))  
1209-6-3、结果输出
python 复制代码
# 1209、pandas.tseries.offsets.SemiMonthEnd.is_quarter_start方法
# True
# True
# False
# True
# True
1210、pandas.tseries.offsets.SemiMonthEnd.is_quarter_end方法
1210-1、语法
python 复制代码
# 1210、pandas.tseries.offsets.SemiMonthEnd.is_quarter_end方法
pandas.tseries.offsets.SemiMonthEnd.is_quarter_end(ts)
Return boolean whether a timestamp occurs on the quarter end.
1210-2、参数

**1210-2-1、ts(必需):**一个Timestamp或者datetime-like对象,表示要检查的日期时间。

1210-3、功能

用于确定给定的日期时间ts是否为该季度的结束日期。

1210-4、返回值

返回一个布尔值,若ts是季度的结束日期,则返回True;反之,则返回False。

1210-5、说明

1210-6、用法
1210-6-1、数据准备
python 复制代码
1210-6-2、代码示例
python 复制代码
# 1210、pandas.tseries.offsets.SemiMonthEnd.is_quarter_end方法
import pandas as pd
# 创建SemiMonthEnd偏移量
semi_month_end = pd.tseries.offsets.SemiMonthEnd()
# 创建测试日期
date_1 = pd.Timestamp('2024-03-31')  # 第一季度结束
date_2 = pd.Timestamp('2024-06-30')  # 第二季度结束
date_3 = pd.Timestamp('2024-04-15')  # 不是季度结束
date_4 = pd.Timestamp('2024-09-30')  # 第三季度结束
date_5 = pd.Timestamp('2024-12-31')  # 第四季度结束
# 检查日期是否为季度结束
print(semi_month_end.is_quarter_end(date_1))  
print(semi_month_end.is_quarter_end(date_2)) 
print(semi_month_end.is_quarter_end(date_3))  
print(semi_month_end.is_quarter_end(date_4))  
print(semi_month_end.is_quarter_end(date_5))  
1210-6-3、结果输出
python 复制代码
# 1210、pandas.tseries.offsets.SemiMonthEnd.is_quarter_end方法 
# True
# True
# False
# True
# True

二、推荐阅读

1、Python筑基之旅
2、Python函数之旅
3、Python算法之旅
4、Python魔法之旅
5、博客个人主页
相关推荐
Hello娃的14 分钟前
【神经网络】人工神经网络ANN
人工智能·深度学习·神经网络
tryxr15 分钟前
继承存在的意义、特点、使用方法
java·开发语言·接口
課代表18 分钟前
Excel VBA 为数据赋予随机浅色标记
excel·vba·可视化·条件格式·标记·对比·随机
lkbhua莱克瓦2421 分钟前
基础-函数
开发语言·数据库·笔记·sql·mysql·函数
RockHopper202521 分钟前
一种认知孪生xLLM架构的原理说明
人工智能·llm·数字孪生·认知孪生
weixin1997010801627 分钟前
哔哩哔哩 item_get_video - 获取视频详情接口对接全攻略:从入门到精通
人工智能·音视频
沛沛老爹29 分钟前
Web开发者实战RAG评估:从指标到工程化验证体系
前端·人工智能·llm·agent·rag·评估
清水白石00833 分钟前
《深入 Python 上下文管理器:contextlib.contextmanager 与类实现方式的底层差异全景解析》
开发语言·python
qq_2004650534 分钟前
日益衰落的五常“礼、义、仁、智、信”,蒸蒸日上的五德“升、悟、净、正、合”
人工智能·起名大师·改名大师·姓名学大师·姓名学专家
程序员佳佳35 分钟前
GPT-4时代终结?GPT-5.2与Banana Pro实测数据公开,普通开发者如何接住这泼天富贵
开发语言·python·gpt·chatgpt·重构·api·midjourney