Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Add hours to time series

I’ve got this following time series[1] which have the timezone in UTC, since my timezone is GMT+1 i would like to add 1 hours to all this time. I try different solutions (like convert it to datetime and add a timedelta) but none of that solutions works. How can i solve this problem, I’ve been working on it all day but can’t find a working solution.

[1]:

import pandas as pd


df = pd.read_csv( "streaming_history_New1.csv", encoding = "ISO-8859-1", sep = ';') 

dfNew = pd.DataFrame(df.end_time.str.split(' ',1).tolist(),columns = ['date','time']

print(dfNew['time'])

0       15:49
1       15:53
2       15:54
3       16:41
4       16:54
 ....
2862    19:16
2863    19:19
2864    19:22
2865    19:24
2866    19:27
Name: time, Length: 2867, dtype: object

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You should first cast the column time to a datetime object and then perform pd.Timedelta increment.

Try this:

from datetime import datetime

d['time_p'] = (d['time'].apply(lambda x: datetime.strptime(x, "%H:%M")) + pd.Timedelta("1 hour")).apply(lambda y: datetime.strftime(y, "%H:%M"))

Column time_p is your expected time column incremented by 1 hour

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading