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、博客个人主页
相关推荐
m0_57046641几秒前
代码随想录算法训练营第二十八天 | 买卖股票的最佳实际、跳跃游戏、K次取反后最大化的数组和
java·开发语言·算法
程序喵大人1 分钟前
分享个C++线程池的实现源码
开发语言·c++·线程池
和鲸社区6 分钟前
《斯坦福CS336》作业1开源,从0手搓大模型|代码复现+免环境配置
人工智能·python·深度学习·计算机视觉·语言模型·自然语言处理·nlp
fanstuck8 分钟前
2025 年高教社杯全国大学生数学建模竞赛C 题 NIPT 的时点选择与胎儿的异常判定详解(一)
人工智能·目标检测·数学建模·数据挖掘·aigc
cxr8289 分钟前
Claude Code PM 深度实战指南:AI驱动的GitHub项目管理与并行协作
人工智能·驱动开发·github
不会吃萝卜的兔子26 分钟前
go webrtc - 1 go基本概念
开发语言·golang·webrtc
豌豆花下猫39 分钟前
Python 潮流周刊#118:Python 异步为何不够流行?(摘要)
后端·python·ai
THMAIL44 分钟前
深度学习从入门到精通 - LSTM与GRU深度剖析:破解长序列记忆遗忘困境
人工智能·python·深度学习·算法·机器学习·逻辑回归·lstm
Gyoku Mint1 小时前
NLP×第六卷:她给记忆加了筛子——LSTM与GRU的贴靠机制
人工智能·深度学习·神经网络·语言模型·自然语言处理·gru·lstm
要做朋鱼燕1 小时前
【C++】 priority_queue 容器模拟实现解析
开发语言·c++·笔记·职场和发展