2
1

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.

Pandasで現在時刻よりn分前の1分間のデータを得る

Posted at

こうしたい

現在時刻より3分前の1分間のデータを取得したい

現在時刻:2017-05-05 15:29:29

ほしい時刻:2017-05-05 15:26:00 ~ 2017-05-05 15:26:59

こうした

import pandas as pd
from datetime import datetime
import pandas.tseries.offsets as offsets

now = pd.to_datetime(datetime.now()) #現在時刻を取得

begin = now.replace(second=0,microsecond=0)-offsets.Minute(3) #3分前の0秒
end   = now.replace(second=59,microsecond=0)-offsets.Minute(3) #3分前の59秒

あとは

df[(df['created_at'] > begin) & (df['created_at'] < end)]

これで任意の時刻の1分間のデータが得られる

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?