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、博客个人主页
相关推荐
IT_陈寒6 小时前
React 18实战:7个被低估的Hooks技巧让你的开发效率提升50%
前端·人工智能·后端
数据智能老司机7 小时前
精通 Python 设计模式——分布式系统模式
python·设计模式·架构
逛逛GitHub7 小时前
飞书多维表“独立”了!功能强大的超出想象。
人工智能·github·产品
机器之心7 小时前
刚刚,DeepSeek-R1论文登上Nature封面,通讯作者梁文锋
人工智能·openai
数据智能老司机8 小时前
精通 Python 设计模式——并发与异步模式
python·设计模式·编程语言
数据智能老司机8 小时前
精通 Python 设计模式——测试模式
python·设计模式·架构
数据智能老司机8 小时前
精通 Python 设计模式——性能模式
python·设计模式·架构
c8i8 小时前
drf初步梳理
python·django
每日AI新事件8 小时前
python的异步函数
python
这里有鱼汤10 小时前
miniQMT下载历史行情数据太慢怎么办?一招提速10倍!
前端·python