我有熊猫系列myS
import pandas as pd
索引是一组仅包含时间的字符串
myS.index
Out[28]:
Index([u'12:00 AM', u'12:14 AM', u'12:18 AM', u'12:25 AM', u'12:26 AM',
u'12:37 AM', u'12:41 AM', u'12:47 AM', u'12:55 AM', u'12:59 AM',
...
u'11:00 PM', u'11:02 PM', u'11:09 PM', u'11:18 PM', u'11:25 PM',
u'11:35 PM', u'11:42 PM', u'11:46 PM', u'11:50 PM', u'11:55 PM'],
dtype='object', name=u'Time (CET)', length=169)
我可以方便地将其正确转换为日期时间:
myS.index= pd.to_datetime(myS.index, format='%I:%M %p')
但是,所有日期都将设置为1900-01-01
'1900-01-01 23:50:00', '1900-01-01 23:55:00'],
dtype='datetime64[ns]',
如果我有可用的日期时间,如何将索引的所有日期重置为所需值,同时保持时间不变?