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
  How to produce a CPU load for several seconds, and measure it? Calab 2 1,580 Jun-18-2025, 02:19 AM
Last Post: Plyth
  Conversion of Oracle PL/SQL(packages, functions, procedures) to python modules. DivyaKumar 3 9,718 Oct-01-2024, 03:32 PM
Last Post: Alex_Kirpichny
  how to correctly set duration of video clips to merge? oxidian 1 2,509 Aug-03-2024, 05:35 PM
Last Post: oxidian
  Problem with module time and leap seconds Pedroski55 3 2,764 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 2,224 Aug-19-2022, 07:52 AM
Last Post: Gribouillis
  How to change UTC time to local time in Python DataFrame? SamKnight 2 3,399 Jul-28-2022, 08:23 AM
Last Post: Pedroski55
  Store variable data and display sum after 60 seconds the_dude 11 7,290 Dec-16-2021, 07:07 PM
Last Post: deanhystad
  Time conversion error tester_V 1 3,083 Oct-28-2020, 10:48 PM
Last Post: tester_V
  How to calculate time difference between each row of dataframe in seconds Mekala 1 4,283 Jul-16-2020, 12:57 PM
Last Post: Larz60+
  Need to add hours min and seconds tester_V 5 5,263 Jun-02-2020, 05:29 PM
Last Post: tester_V

Forum Jump:

User Panel Messages

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