Skip to content
Advertisement

Pandas – What datatype should a duration column (mm:ss) be to use aggregates on it?

I’m doing some NBA analysis and have a “Minutes Played” column for players in a mm:ss format. What dtype should this column be to perform aggregate functions (mean, min, max, etc…) on it? The df has over 20,000 rows, so here is a sample of the column in question:

JavaScript

I ran this code to change the format to datetime –

JavaScript

it changed the dtype successfully, but I am still unable to perform operations on the column. I am met with this error when trying to aggregate the column:

JavaScript

My code for the aggregate

JavaScript

I would like to be able to see the average # of minutes and retain the mm:ss format.

Any help is appreciated.

Advertisement

Answer

JavaScript

output:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement