如何使用 UliEngineering 在 Python 中检查 datetime 是否为年份变更
你可以使用 UliEngineering Python 库轻松地检测 datetime 数组中的年份变更:
is_year_change.py
import numpy as np
from UliEngineering.Utils.Date import *
# 检查 NumPy datetime64 数组
dates = np.array(['2023-12-31', '2024-01-01', '2024-12-31', '2025-01-01'], dtype='datetime64[D]')
result = is_year_change(dates)
print(f"Year change detection: {result}")
# 检查同一年内的连续日期
dates = np.array(['2024-01-01', '2024-01-02', '2024-01-03'], dtype='datetime64[D]')
result = is_year_change(dates)
print(f"No year change: {result}")示例输出
is_year_change_output.txt
Year change detection: [ True True False True]
No year change: [False False False]is_year_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