0
3

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.

【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)")
0
3
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
0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?