2

i have a quick question regarding the timestamps in python pandas

                   date       sometime
   time
03:10:22.227138  20140210  03:10:22.227138
03:10:22.029889  20140211  03:10:22.029889
03:10:22.030458  20140312  03:10:22.030458

How can i add 2 minutes to all the items in the index. i.e., time column?

any quick and neat way to do this?

thanks!

James Bond
  • 7,533
  • 19
  • 50
  • 64
  • a quick hack is found at http://stackoverflow.com/questions/12448592/how-to-add-delta-to-python-datetime-time – James Bond Mar 18 '14 at 14:44

1 Answers1

2

First answer(wrong) Use datetime.replace():

df["time"] = df["time"].apply(lambda x: x.replace(minute=x.minute+2))

This is wrong because the replace function only takes numbers from 0 to 59 as args for minutes.

Edit as the comment suggested:

df["time"] = df["time"].apply(lambda x: x + timedelta(minutes=2))
grasshopper
  • 3,988
  • 3
  • 23
  • 29