add formatted column to pandas data frame - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: add formatted column to pandas data frame (/thread-25179.html) |
add formatted column to pandas data frame - alkaline3 - Mar-22-2020 Hi, I have this example: timeList = [ '0:00:00', '0:00:15', '9:30:56' ] totalSecs = 0 for tm in timeList: timeParts = [int(s) for s in tm.split(':')] totalSecs += (timeParts[0] * 60 + timeParts[1]) * 60 + timeParts[2] totalSecs, sec = divmod(totalSecs, 60) hr, min = divmod(totalSecs, 60) print ("%d:%02d:%02d" % (hr, min, sec))But rather than summing up the values, I'd like to add the formatted values to a new column that I can then work with. How can I do so? |