我有一个numpy.ndarray对象
array([[ 2016., 1., 1.],
[ 2016., 12., 31.]])
有人可以告诉我如何将其转换为日期对象,如
date([2016-01-01],
[2016-12-31])
答案 0 :(得分:0)
请查看这是否是您正在寻找的转换类型:从numpy ndarray到datetime,到string或numpy datetime:
import datetime as dt
import numpy as np
x = np.array([[ 2016., 1., 1.], [ 2016., 12., 31.]])
string = [dt.datetime(*el).strftime('%Y-%m-%d') for el in x.astype(int)]
string
['2016-01-01', '2016-12-31']
datetime = np.array(datetime, dtype='datetime64[D]')
datetime
array(['2016-01-01', '2016-12-31'], dtype='datetime64[D]')