python - how to add hour to pandas dataframe column -


i have pandas dataframe time column following.

 segments_data['time']  out[1585]:   0      04:50:00  1      04:50:00  2      05:00:00  3      05:12:00  4      06:04:00  5      06:44:00  6      06:44:00  7      06:47:00  8      06:47:00  9      06:47:00 

i want add 5 hours , 30 mins above time column. doing following in python.

pd.datetimeindex(segments_data['time']) + pd.dateoffset(hours=5,minutes=30) 

but gives me error.

typeerror: object of type 'datetime.time' has no len() 

please help.

this gnarly way of doing it, principally problem here lack of vectorised support time objects, first need convert time datetime using combine , apply offset , time component back:

in [28]:   import datetime dt   df['new_time'] = df['time'].apply(lambda x: (dt.datetime.combine(dt.datetime(1,1,1), x,) + dt.timedelta(hours=3,minutes=30)).time()) df  out[28]:            time  new_time index                     0      04:50:00  08:20:00 1      04:50:00  08:20:00 2      05:00:00  08:30:00 3      05:12:00  08:42:00 4      06:04:00  09:34:00 5      06:44:00  10:14:00 6      06:44:00  10:14:00 7      06:47:00  10:17:00 8      06:47:00  10:17:00 9      06:47:00  10:17:00 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -