【发布时间】:2020-10-02 08:09:22
【问题描述】:
我正在学习 Pandas,特别是现在使用 Datetimes。我正在寻找一种按日期时间列选择行的方法。如果 Datetime 列的值在数组 spacex 和 clonx 值之间的范围内。
两个数组:
clonx = array(['2019-08-14T23:32:00.000000000', '2019-08-14T23:35:00.000000000',
'2019-08-14T23:35:00.000000000', ...,
'2020-05-24T14:55:00.000000000', '2020-05-24T15:03:00.000000000',
'2020-05-25T12:09:00.000000000'], dtype='datetime64[ns]')
spacex = array(['2019-08-14T23:27:00.000000000', '2019-08-14T23:30:00.000000000',
'2019-08-14T23:30:00.000000000', ...,
'2020-05-24T14:50:00.000000000', '2020-05-24T14:58:00.000000000',
'2020-05-25T12:04:00.000000000'], dtype='datetime64[ns]')
栏目:
first['datim']
0 2019-08-14 23:26:00
1 2019-08-14 23:26:00
2 2019-08-14 23:27:00
3 2019-08-14 23:30:00
4 2019-08-14 23:30:00
...
5101 2020-05-25 20:48:00
5102 2020-05-25 20:49:00
5103 2020-05-26 13:52:00
5104 2020-05-26 13:52:00
5105 2020-05-26 14:22:00
Name: datim, Length: 3172, dtype: datetime64[ns]
如何从 first['datim'] 列中获取位于 spacex 和 clonx 日期时间之间的日期时间值?
类似这样的:
start_date = spacex[i]
end_date = clonx[i]
for i in range:
final = (first['datim'] >= start_date) & (first['datim'] <= end_date)
result final
或者可能使用beween_time,但无法找到使其与数组一起使用的方法。
珍惜你的时间!
【问题讨论】:
-
您是否需要检查
spacex和clonx中的所有值,还是使用.min/.max就足够了? -
感谢您的时间@MrFruppes。它必须在两个数组的值之间,例如:spacex[4] - clonx[4], space[5] - clonx[5],...
标签: python pandas datetime data-science