如何使用 UliEngineering 在 Python 中检查 datetime 是否为月份变更
你可以使用 UliEngineering Python 库轻松地检测 datetime 数组中的月份变更:
is_month_change.py
import numpy as np
from UliEngineering.Utils.Date import *
# 检查 NumPy datetime64 数组
dates = np.array(['2024-01-31', '2024-02-01', '2024-02-28', '2024-03-01'], dtype='datetime64[D]')
result = is_month_change(dates)
print(f"Month change detection: {result}")
# 检查连续日期
dates = np.array(['2024-01-01', '2024-01-02', '2024-01-03'], dtype='datetime64[D]')
result = is_month_change(dates)
print(f"No month change: {result}")示例输出
is_month_change_output.txt
Month change detection: [ True True False True]
No month change: [False False False]is_month_change() 函数对于第一个元素以及与前一个元素相比月份发生变化的每个位置返回 True。
相关文章
- 如何使用 UliEngineering 在 Python 中检查 datetime 是否为每月第一天
- 如何使用 UliEngineering 在 Python 中检查 datetime 是否为年份变更
- 如何使用 UliEngineering 在 Python 中从 NumPy datetime64 数组提取月份
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow