Skip to content
Advertisement

Using python to create an average out of a list of times

I have a huge list of times (HH:MM:SS) and I know that if I wanted to create an average I could separate the Hours, Seconds, and Minutes and average each one and then concatenate them back together. However I feel that there must be a better way to do that. Does anyone know of a better way to do this?

Thanks!

Advertisement

Answer

You don’t want to “average” times on hours, minutes and seconds this way:

JavaScript

average clearly to 01:00:00, but not with the logic you presented.

Instead convert all your time intervals into seconds, calculate the average and convert back to HH:MM:SS.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement