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、博客个人主页
相关推荐
笺上山河梦几秒前
C++ 的 输入输出流(I/O Streams)
开发语言·c++·学习·算法
闭月之泪舞7 分钟前
OpenCv高阶(七)——图像拼接
人工智能·opencv·计算机视觉
智践行10 分钟前
机器人操作系统ROS2之理解动作
人工智能·操作系统
思通数据11 分钟前
开源AI守护童心——幼儿跌倒报警系统的智能安全革命
人工智能·深度学习·安全·目标检测·计算机视觉·目标跟踪·ocr
蚝油菜花11 分钟前
AI生成视频告别剪辑拼接!MAGI-1:开源自回归视频生成模型,支持一镜到底的长视频生成
人工智能·开源
蚝油菜花11 分钟前
「社会实验室」成真!SocioVerse:复旦联合小红书开源社会模拟世界模型,用AI预演群体行为
人工智能·开源
蚝油菜花13 分钟前
机器人训练师狂喜!Infinite Mobility:上海AI Lab造物神器1秒生成可动家具,成本只要1分钱
人工智能·开源
蚝油菜花14 分钟前
白板秒变IDE,草图直接生成可运行代码!Pad.ws:白板+代码编辑器深度结合,创意到实现无缝衔接
人工智能·开源
小杨40415 分钟前
LLM大语言模型三(非技术人视角的大模型解读)
人工智能·python·llm
玄之宵17 分钟前
Android 回显
android·java·开发语言