I have a list of dictionaries:
mylist=
[{'Start Time': '02:13:40', 'End Time': '14:13:10'},
{'Start Time': '03:12:30', 'End Time': '13:07:45'},
{'Start Time': '05:03:20', 'End Time': '17:23:10'},
...
{'Start Time': '08:23:40', 'End Time': '19:23:40'}]
I wanted to append a new column that records the time difference between Start Time and End Time. I tried the following:
dfmylist = pd.DataFrame(mylist)
dfmylist["new"] = (dfmylist['End Time'] - dfmylist['Start Time'])
It gave me the error: TypeError: unsupported operand type(s) for -: 'str' and 'str'
I think it is because the time data has not been converted to string, so I tried the following:
dfmylist['Start Time'] = pd.to_timedelta(dfmylist['Start Time'] ).dt.strftime('%hh:%mm:%ss')
But I received the error: ValueError: expected hh:mm:ss format