我在python中有一个datetime数组:
array([datetime.datetime(2017, 3, 25, 9, 0),
datetime.datetime(2017, 3, 25, 12, 0),
datetime.datetime(2017, 3, 25, 15, 0),
datetime.datetime(2017, 3, 25, 18, 0),
datetime.datetime(2017, 3, 25, 21, 0),
datetime.datetime(2017, 3, 26, 0, 0),
datetime.datetime(2017, 3, 26, 3, 0),
datetime.datetime(2017, 3, 26, 6, 0),
datetime.datetime(2017, 3, 26, 9, 0),
datetime.datetime(2017, 3, 26, 12, 0),
datetime.datetime(2017, 3, 26, 15, 0),
datetime.datetime(2017, 3, 26, 18, 0),
datetime.datetime(2017, 3, 26, 21, 0),
datetime.datetime(2017, 3, 27, 0, 0),
datetime.datetime(2017, 3, 27, 3, 0),
datetime.datetime(2017, 3, 27, 6, 0),
datetime.datetime(2017, 3, 27, 9, 0),
datetime.datetime(2017, 3, 27, 12, 0),
datetime.datetime(2017, 3, 27, 15, 0),
datetime.datetime(2017, 3, 27, 18, 0),
datetime.datetime(2017, 3, 27, 21, 0),
datetime.datetime(2017, 3, 28, 0, 0)], dtype=object)
如何将其转换为dattetimeindex:
DatetimeIndex(['2017-03-25 06:47:11.454232', '2017-03-26 06:47:11.454232',
'2017-03-27 06:47:11.454232', '2017-03-28 06:47:11.454232',
'2017-03-29 06:47:11.454232', '2017-03-30 06:47:11.454232',
'2017-03-31 06:47:11.454232'],
dtype='datetime64[ns]', freq='D')
答案 0 :(得分:0)
就这样做:
compagnie = Compagnie('nom','actions','prix')
compagnie.setActions()
好吧,有人请求解释为什么这行得通,但我对此没有深入的了解……嗯,历史很短,我的工作需要它,发现它运行得很好,并且对我来说足够了...但是如果有人需要更深入的知识,他/她可以查看 Pandas 文档网站,其中有很好的解释:
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html