我有彼此相邻的两列数组(日期和时间),我需要将它们转换为日期时间对象,以便可以使用它们在x轴上绘制图形。 这些数据在不断更新,因此它们不是固定数字,只是固定。

datetime = np.column_stack((date,time))
datetime = np.array(datetime)
datetime
    array([[b'143.0', b'08:15'],
       [b'143.0', b'08:30'],
       [b'143.0', b'08:45'],
       [b'143.0', b'09:00'],
       [b'143.0', b'09:15'],
       [b'143.0', b'09:30'],
       [b'143.0', b'09:45'],
       [b'143.0', b'10:00'],
       [b'143.0', b'10:15'],
       [b'143.0', b'10:30'],
       [b'143.0', b'10:45'],
       [b'143.0', b'11:00'],
       [b'143.0', b'11:15'],
       [b'143.0', b'11:30'],
       [b'143.0', b'11:45'],
       [b'143.0', b'12:00'],
       [b'143.0', b'12:15'],
       [b'143.0', b'12:30'],
       [b'143.0', b'12:45'],
       [b'143.0', b'13:00'],
       [b'143.0', b'13:15'],
       [b'143.0', b'13:30'],
       [b'143.0', b'13:45'],
       [b'143.0', b'14:00'],
       [b'143.0', b'14:15'],
       [b'143.0', b'14:30'],
       [b'143.0', b'14:45'],
       [b'143.0', b'15:00'],
       [b'143.0', b'15:15'],
       [b'143.0', b'15:30'],
       [b'143.0', b'15:45'],
       [b'143.0', b'16:00'],
       [b'143.0', b'16:15'],
       [b'143.0', b'16:30'],
       [b'143.0', b'16:45'],
       [b'143.0', b'17:00'],
       [b'143.0', b'17:15'],
       [b'143.0', b'17:30'],
       [b'143.0', b'17:45'],
       [b'143.0', b'18:00'],
       [b'143.0', b'18:15'],
       [b'143.0', b'18:30'],
       [b'143.0', b'18:45'],
       [b'143.0', b'19:00'],
       [b'143.0', b'19:15'],
       [b'143.0', b'19:30'],
       [b'143.0', b'19:45'],
       [b'143.0', b'20:00'],
       [b'143.0', b'20:15'],
       [b'143.0', b'20:30'],
       [b'143.0', b'20:45'],
       [b'143.0', b'21:00'],
       [b'143.0', b'21:15'],
       [b'143.0', b'21:30'],
       [b'143.0', b'21:45'],
       [b'143.0', b'22:00'],
       [b'143.0', b'22:15'],
       [b'143.0', b'22:30'],
       [b'143.0', b'22:45'],
       [b'143.0', b'23:00'],
       [b'143.0', b'23:15'],
       [b'143.0', b'23:30'],
       [b'143.0', b'23:45'],
       [b'144.0', b'00:00'],
       [b'144.0', b'00:15'],
       [b'144.0', b'00:30'],
       [b'144.0', b'00:45'],
       [b'144.0', b'01:00'],
       [b'144.0', b'01:15'],
       [b'144.0', b'01:30'],
       [b'144.0', b'01:45'],
       [b'144.0', b'02:00'],
       [b'144.0', b'02:15'],
       [b'144.0', b'02:30'],
       [b'144.0', b'02:45'],
       [b'144.0', b'03:00'],
       [b'144.0', b'03:15'],
       [b'144.0', b'03:30'],
       [b'144.0', b'03:45'],
       [b'144.0', b'04:00'],
       [b'144.0', b'04:15'],
       [b'144.0', b'04:30'],
       [b'144.0', b'04:45'],
       [b'144.0', b'05:00'],
       [b'144.0', b'05:15'],
       [b'144.0', b'05:30'],
       [b'144.0', b'05:45'],
       [b'144.0', b'06:00'],
       [b'144.0', b'06:15'],
       [b'144.0', b'06:30'],
       [b'144.0', b'06:45'],
       [b'144.0', b'07:00'],
       [b'144.0', b'07:15'],
       [b'144.0', b'07:30'],
       [b'144.0', b'07:45'],
       [b'144.0', b'08:00'],
       [b'144.0', b'08:15'],
       [b'144.0', b'08:30'],
       [b'144.0', b'08:45'],
       [b'144.0', b'09:00'],
       [b'144.0', b'09:15'],
       [b'144.0', b'09:30'],
       [b'144.0', b'09:45'],
       [b'144.0', b'10:00'],
       [b'144.0', b'10:15'],
       [b'144.0', b'10:30'],
       [b'144.0', b'10:45'],
       [b'144.0', b'11:00'],
       [b'144.0', b'11:15'],
       [b'144.0', b'11:30'],
       [b'144.0', b'11:45'],
       [b'144.0', b'12:00'],
       [b'144.0', b'12:15'],
       [b'144.0', b'12:30'],
       [b'144.0', b'12:45'],
       [b'144.0', b'13:00'],
       [b'144.0', b'13:15'],
       [b'144.0', b'13:30'],
       [b'144.0', b'13:45'],
       [b'144.0', b'14:00'],
       [b'144.0', b'14:15'],
       [b'144.0', b'14:30'],
       [b'144.0', b'14:45'],
       [b'144.0', b'15:00'],
       [b'144.0', b'15:15'],
       [b'144.0', b'15:30'],
       [b'144.0', b'15:45'],
       [b'144.0', b'16:00'],
       [b'144.0', b'16:15'],
       [b'144.0', b'16:30'],
       [b'144.0', b'16:45'],
       [b'144.0', b'17:00'],
       [b'144.0', b'17:15'],
       [b'144.0', b'17:30'],
       [b'144.0', b'17:45'],
       [b'144.0', b'18:00'],
       [b'144.0', b'18:15'],
       [b'144.0', b'18:30'],
       [b'144.0', b'18:45'],
       [b'144.0', b'19:00'],
       [b'144.0', b'19:15'],
       [b'144.0', b'19:30'],
       [b'144.0', b'19:45'],
       [b'144.0', b'20:00'],
       [b'144.0', b'20:15'],
       [b'144.0', b'20:30'],
       [b'144.0', b'20:45'],
       [b'144.0', b'21:00'],
       [b'144.0', b'21:15'],
       [b'144.0', b'21:30'],
       [b'144.0', b'21:45'],
       [b'144.0', b'22:00'],
       [b'144.0', b'22:15'],
       [b'144.0', b'22:30'],
       [b'144.0', b'22:45'],
       [b'144.0', b'23:00'],
       [b'144.0', b'23:15'],
       [b'144.0', b'23:30'],
       [b'144.0', b'23:45'],
       [b'145.0', b'00:00'],
       [b'145.0', b'00:15'],
       [b'145.0', b'00:30'],
       [b'145.0', b'00:45'],
       [b'145.0', b'01:00'],
       [b'145.0', b'01:15'],
       [b'145.0', b'01:30'],
       [b'145.0', b'01:45'],
       [b'145.0', b'02:00'],
       [b'145.0', b'02:15'],
       [b'145.0', b'02:30'],
       [b'145.0', b'02:45'],
       [b'145.0', b'03:00'],
       [b'145.0', b'03:15'],
       [b'145.0', b'03:30'],
       [b'145.0', b'03:45'],
       [b'145.0', b'04:00'],
       [b'145.0', b'04:15'],
       [b'145.0', b'04:30'],
       [b'145.0', b'04:45'],
       [b'145.0', b'05:00'],
       [b'145.0', b'05:15'],
       [b'145.0', b'05:30'],
       [b'145.0', b'05:45'],
       [b'145.0', b'06:00'],
       [b'145.0', b'06:15'],
       [b'145.0', b'06:30'],
       [b'145.0', b'06:45'],
       [b'145.0', b'07:00'],
       [b'145.0', b'07:15'],
       [b'145.0', b'07:30'],
       [b'145.0', b'07:45'],
       [b'145.0', b'08:00']], 
      dtype='|S32')

第一列是儒略时间,因此基本上是今天之后的最后3天,因为它会更新为包括最近的3天。 任何帮助将不胜感激。

===============>>#1 票数:0 已采纳

您可以先使用列表推导将数据重塑为与numpy的datetime64类型兼容的格式,然后使用该格式创建一个数组。 看起来numpy不能与Python中的普通datetime.datetime一起使用。

不能完全确定朱利安时间的工作方式,但是我假设您的第一列是从年初开始的一天。 这应该给您您想要的。

from datetime import datetime, timedelta
data = [[b'143.0', b'08:15'], [b'143.0', b'08:30']...]

base = datetime(2016, 1, 1, 0, 0, 0, 0)
transformed = [(base + timedelta(days=int(float(x)), hours=int(y[0:2]), minutes=int(y[3:5]))).isoformat() for x, y in data]

my_array = np.array(transformed, dtype='datetime64')

  ask by King Andy translate from so

未解决问题?本站智能推荐: