Python Forum

Full Version: Conversion of Time Duration in seconds in python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?