Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

こうしたい

現在時刻より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分間のデータが得られる

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away