Home > Blockchain >  Pandas DataFrame Time Conversion
Pandas DataFrame Time Conversion

Time:08-18

How to change for example '01:31:41' the value display in stopwatch which is into seconds value. E.g this is 1 min and 31 second, so roughly about 91 seconds.

CodePudding user response:

do you want the output to be 1 min and 31 seconds or 91 seconds? Also please provide some code for what you have tried so we can better help.

CodePudding user response:

split string into a list object create a timedelta object without miliseconds as they aren't needed we use the self method of timedelta total_seconds()

from datetime import timedelta
original_time_string = "01:30:12"
list_string = original_time_string.split(":")
print((timedelta(minutes=int(list_string[0]),seconds=int(list_string[1])).total_seconds()))
  • Related