gpt4 book ai didi

python - 我怎样才能只获取不到两年的日期?

转载 作者:行者123 更新时间:2023-12-02 18:28:32 25 4
gpt4 key购买 nike

np_arr = np.array([
[2818, 'Daniel', 'within an hour', '2008-09-24', 4.89, 2.86, 't', 't'],
[5820, 'Sam', 'within an week', '2020-10-24', 4.89, 2.86, 't', 't'],
[5420, 'Franc', 'within an second', '2019-11-24', 4.89, 2.86, 't', 't'],
[5520, 'Sandra', 'within an second', '2019-01-24', 4.89, 2.86, 't', 't']
])
host_since = np_arr[:,3].astype(np.datetime64)
filter = (datetime.now() - host_since.astype('datetime64[M]')).years < 2
filter

如何才能只获取不到两年的日期?True/False 数组应如下所示:

array([[False, True, True, False])

最佳答案

看起来您将年份定义为 12 个月。然后尝试:

month_diff = np.array(datetime.now(), 'datetime64[M]') - host_since.astype('datetime64[M]')

mask = month_diff < np.array(24, 'timedelta64[M]')

输出:

array([False,  True,  True, False])

关于python - 我怎样才能只获取不到两年的日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69758076/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com