Python Forum
Conversion of Time Duration in seconds in python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Conversion of Time Duration in seconds in python
#1
import re
match = re.match(r'PT(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?', 'PT7M37S')
(hours, minutes, seconds) = [ int(n or 0) for n in match.groups() ]
A=hours*60*60+ minutes*60+ seconds

This works for a single string.

But i have a dataset, with multiple columns, and i want to apply this operation to one of the columns in the dataset. Can anybody tell me how will that work?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with module time and leap seconds Pedroski55 3 1,189 Oct-07-2022, 11:27 PM
Last Post: Pedroski55
  I need to add data types to cython conversion python to c Good_AI_User 1 973 Aug-19-2022, 07:52 AM
Last Post: Gribouillis
  How to change UTC time to local time in Python DataFrame? SamKnight 2 1,527 Jul-28-2022, 08:23 AM
Last Post: Pedroski55
  Store variable data and display sum after 60 seconds the_dude 11 3,365 Dec-16-2021, 07:07 PM
Last Post: deanhystad
  Time conversion error tester_V 1 1,988 Oct-28-2020, 10:48 PM
Last Post: tester_V
  How to calculate time difference between each row of dataframe in seconds Mekala 1 2,514 Jul-16-2020, 12:57 PM
Last Post: Larz60+
  Conversion of Oracle PL/SQL(packages, functions, procedures) to python modules. DivyaKumar 2 6,412 Jul-09-2020, 04:46 PM
Last Post: srikanth7482
  Need to add hours min and seconds tester_V 5 3,029 Jun-02-2020, 05:29 PM
Last Post: tester_V
  C to Python code conversion print problem anakk1n 1 2,137 May-22-2020, 04:15 PM
Last Post: deanhystad
  Python uppercase conversion conditions Jaypeng 7 2,891 Apr-29-2020, 11:24 AM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020