LoginSignup
1
0

More than 1 year has passed since last update.

【備忘録】Python Pandasでindex以外の列を指定してbetween_timeを実行する

Posted at

between_timeのパラメーターにはindex列以外が指定できない…

between_time(start_time、 end_time、 include_start = True、 include_end = True、 axis = None)

パラメーター
start_timedatetime.timeまたはstr
時間フィルター制限としての初期時間。

end_timedatetime.timeまたはstr
時間フィルター制限としての終了時間。

include_start bool、デフォルトはTrue
開始時刻を結果に含める必要があるかどうか。

include_end bool、デフォルトはTrue
終了時刻を結果に含める必要があるかどうか。

axis {0または 'index'、1または 'columns'}、デフォルトは0
インデックスまたは列の値の範囲時間を決定します。

ここから、index以外の行を指定する場合によくみられるコードはこちら。

df.set_index(keys='my_datetime_field').between_time('8:00','21:00').reset_index()

よりスマートに記述するには…

index = pd.DatetimeIndex(df['date'])
df.iloc[index.indexer_between_time('8:00','21:00')]

index.indexer_between_timeがめっちゃ便利!

DatetimeIndex。indexer_between_time(start_time、 end_time、 include_start = True、 include_end = True)[ソース]¶
特定の時刻(たとえば、9:00-9:30AM)の間の値のインデックス位置を返します。

パラメーター
start_time、end_time datetime.time、str
オブジェクト(datetime.time)または適切な形式の文字列( "%H:%M"、 "%H%M"、 "%I:%M%p"、 "%I%M%p"のいずれかとして経過した時間、「%H:%M:%S」、「%H%M%S」、「%I:%M:%S%p」、「%I%M%S%p」)。

include_start bool、デフォルトはTrue
include_end bool、デフォルトはTrue
戻り値
np.ndarray [np.intp]

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