11
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

timedeltaの変換

Last updated at Posted at 2019-06-14

timestampの差を取る

データセットとしてtimestampをもらったときにその工程間の差を特徴量に使いたい。

しかしながらtimestamp同士の差をとるとtimedelta型になってしまいその後の正規化などが面倒なので秒数に変換したい。

total_seconds()

timedelta型のメソッドtotal_seconds()を使えば解決する。

diff_time = '7 days 00:56:49.317000'
# Timedelta
diff_time.total_seconds()
# 60829.317

DataFrameでtotal_seconds()を適応したい

dtを使う

diff_time
'''
0    6 days 23:10:44.847000
1    7 days 00:56:49.317000
2    5 days 03:00:34.800000
dtype: timedleta64[ns]
'''

diff_time.dt.total_seconds()
'''
0    601844.847
1    608209.317
2    442834.800
dtype: float64
'''
11
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?