본문 바로가기

Python

[Python] timedelta to int/ timedelta to seconds

방법 1

 

 

td.seconds + td.days*24*3600 #days*24시간*60분*60초

 

- td.seconds를 사용하면 분단위까지 포함하여 계산된다.

ex) 2분 30초 -> td.seconds은 30초가 아닌 150초가 반환됨

 

방법 2

 

(td / np.timedelta64(1,'s')).astype(int)