I have created a list of timedelta objects and i need to get the average of this list. when i try to do
return (sum(delta_list)/(len(delta_list)-1))
i get
TypeError: unsupported operand type(s) for +: 'int' and 'datetime.timedelta'
I am new at working with python’s datetime classes. I also would like to know how to get this average into a format like days: hours: mins: i don’t need anything smaller than mins.
sumwants a starting value, which is0by default, but0can’t be added to atimedeltaso you get the error.You just have to give
sumatimedelta()as the start value:To print it out you can do this:
If you want something customized you can get
some_delta.daysandsome_delta.secondsbut you have to calculate everything between.