I have a dataframe, Date index type is Timestamp, Time column is datetime.Time:
Time Value
Date
2004-05-01 0:15 3.58507
2004-05-02 0:30 3.84625
...
How do I convert it to:
Value
Date
2004-05-01 0:15 3.74618
2004-05-01 0:30 3.58507
2004-05-01 0:45 3.30998
I wrote a code which does work, but it's not very pythonic:
ind = frame.index.get_level_values(0).tolist()
tms = frame['Time']
new_ind = []
for i in range(0, len(ind)):
tm = tms[i]
val = ind[i] + timedelta(hours=tm.hour, minutes=tm.minute, seconds=tm.second)
new_ind.append(val)
frame.index = new_ind
del frame['Time']
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…