Time data is read in string format, converted to datetime format
data['time1'= pd.to_datetime (data['time1'],format=" %h:%m:%s:%f")
Calculate the time difference:
data['time_interval']=pd.to_datetime (data['time2')- Pd.to_datetime (data['time1')
Result: Unit or millisecond
To convert it further into seconds
Supplemental Learning:
Python Time Strptime () methodDescribe
The Python time strptime () function resolves a timing string to a time tuple based on the specified format.
Grammar
Strptime () method syntax:
Time. Strptime(string[, format])
Parameters
- String--time string.
- Format--a formatted string.
return value
Returns the Struct_time object.
Description
Python format symbols in time Date:
- %y Two-digit year representation (00-99)
- %Y Four-digit year representation (000-9999)
- %m Month (01-12)
- One day in%d months (0-31)
- %H 24-hour hours (0-23)
- %I 12-hour hours (01-12)
- %M minutes (00=59)
- %s seconds (00-59)
- %a Local Simplified Week name
- %A Local Full week name
- %b a locally simplified month name
- %B Local Full month name
- %c Local corresponding date representation and time representation
- %j Day of the Year (001-366)
- %p the equivalent of a local a.m. or p.m.
- %u weeks of the year (00-53) Sunday is the beginning of the week
- %w Week (0-6), Sunday for the beginning of the week
- %W Week of the Year (00-53) Monday is the beginning of the week
- %x Local corresponding date representation
- %x Local corresponding time representation
- %Z the name of the current time zone
- Percent% of the number itself
Instance
The following example shows how the Strptime () function is used:
Instance (Python 2.0+)< Span class= "Hl-code" > struct _time = time. Strptime ( "30 Nov 00 "" %d%b%y ")
Python datetime Time Processing