如何使用 UliEngineering 在 Python 中从 NumPy datetime64 数组提取月份中的日期
你可以使用 UliEngineering Python 库轻松从 NumPy datetime64 数组中提取月份中的日期分量:
extract_day_of_month.py
import numpy as np
from UliEngineering.Utils.Date import *
# 创建 datetime64 数组
dates = np.array(['2024-01-15', '2024-06-20', '2024-12-31'], dtype='datetime64[D]')
# 提取月份中的日期
days = extract_day_of_month(dates)
print(f"Dates: {dates}")
print(f"Day of month: {days}")示例输出
extract_day_of_month_output.txt
Dates: ['2024-01-15' '2024-06-20' '2024-12-31']
Day of month: [15 20 31]extract_day_of_month() 函数返回一个 NumPy 数组,包含输入数组中每个 datetime64 值对应的月份中的日期(1-31)。
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow