I have to analyze some logs and based on that, I have to calculate something and I am stuck with one thing. Here I am trying to re-create my problem in a simple form. Suppose I have the following logs in "stackoverflow.txt" file
23:58:03.458
23:58:13.446
23:58:23.447
23:58:33.440
23:58:43.440
23:58:53.440
23:59:03.434
23:59:13.435
23:59:23.428
23:59:33.428
23:59:43.429
23:59:53.435
00:00:03.429
00:00:13.423
00:00:23.417
00:00:33.411
00:00:43.418
00:00:53.411
00:01:03.405
00:01:13.406
00:01:23.400
00:01:33.406
00:01:43.400
00:01:53.411
00:02:03.400
00:02:13.406
00:02:23.394
00:02:33.400
00:02:43.394
I used the following Python program, to convert this time into milliseconds.
import pandas as pd
df = pd.read_csv("stackoverflow.txt", header=None)
# Split Time String into Hour Minutes Seconds and Milliseconds
new_df = df[0].str.split(":", n=-1, expand=True)
df['Hours'] = new_df[0]
df['Minutes'] = new_df[1]
# Split Seconds.Milliseconds information into Seconds and Milliseconds separately
new_df = new_df[2].str.split(".", n=-1, expand=True)
df['Seconds'] = new_df[0]
df['Milliseconds'] = new_df[1]
# These generated data frames are string, convert them into Integers
# df['Hours'] = df['Hours'].apply(lambda x: int(x,10))
# Another way of doing, good thing is that both are consuming same amount of time, checked using %time
df['Hours'] = pd.to_numeric(df['Hours'], errors='coerce')
df['Minutes'] = pd.to_numeric(df['Minutes'], errors='coerce')
df['Seconds'] = pd.to_numeric(df['Seconds'], errors='coerce')
df['Milliseconds'] = pd.to_numeric(df['Milliseconds'], errors='coerce')
# Calculate Total Time
df['Total Time(ms)'] = df['Hours']*3600000 + df['Minutes']*60000 + df['Seconds']*1000 + df['Milliseconds']
df
The Output is as below:
0 Hours Minutes Seconds Milliseconds Total Time(ms)
0 23:58:03.458 23 58 3 458 86283458
1 23:58:13.446 23 58 13 446 86293446
2 23:58:23.447 23 58 23 447 86303447
3 23:58:33.440 23 58 33 440 86313440
4 23:58:43.440 23 58 43 440 86323440
5 23:58:53.440 23 58 53 440 86333440
6 23:59:03.434 23 59 3 434 86343434
7 23:59:13.435 23 59 13 435 86353435
8 23:59:23.428 23 59 23 428 86363428
9 23:59:33.428 23 59 33 428 86373428
10 23:59:43.429 23 59 43 429 86383429
11 23:59:53.435 23 59 53 435 86393435
12 00:00:03.429 0 0 3 429 3429
13 00:00:13.423 0 0 13 423 13423
14 00:00:23.417 0 0 23 417 23417
15 00:00:33.411 0 0 33 411 33411
16 00:00:43.418 0 0 43 418 43418
17 00:00:53.411 0 0 53 411 53411
18 00:01:03.405 0 1 3 405 63405
19 00:01:13.406 0 1 13 406 73406
20 00:01:23.400 0 1 23 400 83400
21 00:01:33.406 0 1 33 406 93406
22 00:01:43.400 0 1 43 400 103400
23 00:01:53.411 0 1 53 411 113411
24 00:02:03.400 0 2 3 400 123400
25 00:02:13.406 0 2 13 406 133406
26 00:02:23.394 0 2 23 394 143394
27 00:02:33.400 0 2 33 400 153400
28 00:02:43.394 0 2 43 394 163394
But I want to add 24 hours whenever there is a change in day from 23:59 to 00:00. I am not able to understand, how I will be able to do this. Can someone please help me in achieving this?