paranormaldist
paranormaldist

Reputation: 508

Pandas timedelta column convert hours and minutes to integer format

I know there are similar questions posted, but not exactly lining up to my use case.

I have a pandas column of timedelta values :

0 days 10:46:22.000000000

That I would like to look like an integer:

10.46

Is there a simple way to do so by extracting hours and minutes?

Upvotes: 0

Views: 908

Answers (1)

Jon Clements
Jon Clements

Reputation: 142226

Convert your Timedeltas to seconds and divide by 3600:

s = pd.Series([pd.Timedelta('0 days 10:46:22.000000000'), pd.Timedelta('5 days 100:31:22.000000000')])

float_hours = s.dt.total_seconds() / 3600

Gives:

0     10.772778
1    220.522778
dtype: float64

Upvotes: 2

Related Questions