LoginSignup
3

More than 3 years have passed since last update.

【Python Pandas メモ】DataFrameで日付型項目で検索する方法

Last updated at Posted at 2019-10-02

始めに

Python DataFrameに読み込んだ日付型の項目で絞り込みをする方法に手間取ったので、その時のメモ。

ポイント1

日付型データは pd.to_datetime関数を使って列ごと型変換する。

from ibmdbpy import IdaDataBase, IdaDataFrame
idadb = ... # (省略)

df_plan = IdaDataFrame(idadb, 'TBL_RESULT').as_dataframe()
df_plan['CREATE_DATE'] = pd.to_datetime(df_plan['CREATE_DATE'])

ポイント2

検索時は検索条件側も datetime.date関数で変換した値を使う。

import datetime

w1= df_plan.query("EMPLOYEE_CD=='1234' and CREATE_DATE==datetime.date(2019,1,10)")

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
3