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、博客个人主页
相关推荐
悟能不能悟1 分钟前
jdk25结构化并发和虚拟线程如何配合使用?有什么最佳实践?
java·开发语言
图扑软件8 分钟前
热力图可视化为何被广泛应用?| 图扑数字孪生
大数据·人工智能·信息可视化·数字孪生·可视化·热力图·电力能源
qq_4369621810 分钟前
AI驱动数据分析革新:奥威BI一键生成智能报告
人工智能·信息可视化·数据分析
柠檬071111 分钟前
MATLAB相机标定入门:Camera Calibration工具包详解
开发语言·数码相机·matlab
卓码软件测评20 分钟前
借助大语言模型实现高效测试迁移:Airbnb的大规模实践
开发语言·前端·javascript·人工智能·语言模型·自然语言处理
小白狮ww22 分钟前
dots.ocr 基于 1.7B 参数实现多语言文档处理,性能达 SOTA
人工智能·深度学习·机器学习·自然语言处理·ocr·小红书·文档处理
hrrrrb23 分钟前
【机器学习】无监督学习
人工智能·学习·机器学习
IT_陈寒25 分钟前
SpringBoot 3.0实战:这套配置让我轻松扛住百万并发,性能提升300%
前端·人工智能·后端
熙客25 分钟前
Java8:Lambda表达式
java·开发语言
小咕聊编程29 分钟前
【含文档+PPT+源码】基于java web的篮球馆管理系统系统的设计与实现
java·开发语言