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

Generate a column of uniform timestamps between 2 time stamps

I have a dataset that does not have a time per each record. I however know the start and end time of the data. I also assume that all data points are recorded in equal intervals. Hence I would like to generate a new column ‘time’ of equally separated times between the start time and end time.

start_time= '2022:01:01:07:30'
end_time='2022:01:01:08:30'

data = {'rec' : ['rec1' for i in range(11)] ,
        'readvalue' : [0.5 + 0.5*np.sin(2*np.pi/10*i) 
                       for i in range(11)]}
df = pd.DataFrame(data, columns = [ 'rec', 'readvalue'])
df

>Solution :

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

You could use date_range:

df['time'] = pd.date_range(start='2022/01/01 07:30', end='2022/01/01 08:30', periods=len(df))

Output:

     rec  readvalue                time
0   rec1   0.500000 2022-01-01 07:30:00
1   rec1   0.793893 2022-01-01 07:36:00
2   rec1   0.975528 2022-01-01 07:42:00
3   rec1   0.975528 2022-01-01 07:48:00
4   rec1   0.793893 2022-01-01 07:54:00
5   rec1   0.500000 2022-01-01 08:00:00
6   rec1   0.206107 2022-01-01 08:06:00
7   rec1   0.024472 2022-01-01 08:12:00
8   rec1   0.024472 2022-01-01 08:18:00
9   rec1   0.206107 2022-01-01 08:24:00
10  rec1   0.500000 2022-01-01 08:30:00
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