How to calculate average of a timedelta column?

91 Views Asked by At

I want to remove the '0 days' from my results, while being able to perform calculations with the formatted results

0 0 days 00:27:00 1 0 days 01:22:00 2 0 days 00:52:00 3 0 days 01:04:00 4 0 days 00:07:00 Name: Tempo Formatado, dtype: timedelta64[ns]

This is the result that I expected:

00:27:00 01:22:00 00:52:00 01:04:00 00:07:00

and being able to calculate the average, which in this case is 00:46

1

There are 1 best solutions below

0
gtomer On

It is hard to help without sample of your data, but let's assume your column is called 'time'. Then:

df['numeric_time'] = df['time'].values.astype(np.int64)
pd.to_timedelta(df['numeric_time'].mean())