Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Do I Format a pandas timedelta object?

I am using pandas timedelta objects to keep track of split times in a sports related data set using the following sort of construction:

import pandas as pd
pd.to_timedelta("-0:0:1.0")

This natively reports as:

-1 days +23:59:59

I can get the raw seconds count using pd.to_timedelta("-0:0:1.0").total_seconds() but that is unwieldy where the negative amount is in minutes or hours:

For the expression:

pd.to_timedelta("-1:2:3.0")

how can I get the report formatted as"-1:2:3.0, or -1 hour, 2 minutes, 3 seconds, from the timedelta object, rather than in the form -3723.0000000000005 (with a float error) or -1 days +22:57:57?

like image 593
psychemedia Avatar asked Jan 21 '17 18:01

psychemedia


1 Answers

See the function strfdelta(tdelta, fmt) provided as an answer to a related question: https://stackoverflow.com/a/8907269/454773

like image 148
psychemedia Avatar answered Sep 21 '22 23:09

psychemedia