Aggregations For Timedelta Values In The Python DataFrame
I have big DataFrame (df) which looks like: Acc_num date_diff 0 29 0:04:43 1 29 0:01:43 2 29 2:22:45 3 29 0:16:21 4 29 0:58:20 5 30 0:00:35 6 34 7:15:26 7
Solution 1:
Weird limitation indeed. But a simple solution would be:
df.groupby('Acc_num').date_diff.agg(lambda g:g.sum()/g.count())
Edit:
Pandas will actually attempt to aggregate non-numeric columns if you pass numeric_only=False
df.groupby('Acc_num').date_diff.mean(numeric_only=False)
Post a Comment for "Aggregations For Timedelta Values In The Python DataFrame"