Find the Average duration of a dataframe column

Hello! I have a dataframe called Jan_df with a column called “Roll Time” which has values of time duration as minutes:seconds. For example 15:42 means 15 minutes and 42 seconds. The data type of this column is “object” (string).

I would like to get the average duration of all the values in this column. I tried this:

Jan_Avg_Roll_Time = Jan_df['ROLL TIME'].mean()

But I get an error saying TypeError : Could not convert the values to numeric.

So I tried:

Jan_df['ROLL TIME'] = Jan_df['ROLL TIME'].astype(int)

But this gave ValueError : invalid literal for int() with base 10: ‘16:41’

(16:42 was the first value in the column).

So what can I do to actually get the average of this column successfully?

Thanks so much for any insights!

Howdy Alex,

is this:

import numpy

column = numpy.array(("16:32", "10:24", "00:39"))

def convertToSeconds(timeS):

    timeT = timeS.split(":")

    return ( int(timeT[0]) * 60 + int(timeT[1]) )

seconds = numpy.vectorize( convertToSeconds )

print( int(seconds(column).mean().round()) )

what you are looking for?

Cheers, Dominik