User groupby and mean
import pandas as pd
from io import StringIO
#Data preprocessing(ignore)
data = StringIO('''
2018-01-01 ,0 days 00:58:26
2018-01-01 ,0 days 01:27:04
2018-01-01 ,0 days 00:17:27
2018-01-01 ,0 days 00:14:26
2018-01-01 ,0 days 01:08:33
''')
#Converting to datetime and timedelta object
df = pd.read_csv(data,names=['date','delivery_time'],parse_dates=['date'])
df['delivery_time'] = pd.to_timedelta(df['delivery_time'])
#Grouping by date and then finding mean of delivery time
df.groupby(['date']).mean(numeric_only=False)
Output:
delivery_time
date
2018-01-01 0 days 00:49:11.200000
using dt.components
you can easily extract hours minutes and seconds from your timedelta
column. Something like following should generate your result.
df.groupby(['date']).mean(numeric_only=False)['delivery_time'].dt.components.iloc[:, 1:4]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…