実行したいこと
DataFrameから期間を範囲指定して抽出したい
###データ内容
python
1df['購入日'] = pd.to_datetime(df['購入日'].astype('str'),errors='coerce') 2→上記コードでデータ型をdatetime64[ns]に 3 4 購入日 54 2017-01-21 65 2017-01-22 76 2017-01-22 87 2017-01-22 98 2017-01-22 109 2017-01-23 1110 2017-01-23 1211 2017-01-23 13dtype: datetime64[ns]
###試したこととその結果発生したエラー
python
1-1 2print(df['2017-01-22':'2017-01-23']) 3 4AttributeError: cannot do slice indexing on <class 'pandas.core.indexes.numeric.Int64Index'> with these indexers [2017-07-08] of <class 'str'> 5 6-2 7df[df['購入日'] > datetime(2017, 01, 22)] 8 9AttributeError: 'module' object is not callable 10 11-3 12df[df['購入日'] > df['購入日'].dt.datetime('2017-01-22')] 13 14AttributeError: 'DatetimeProperties' object has no attribute 'datetime'
どこに問題があるのか教えていただければ幸いです。
宜しくお願い致します。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2019/07/26 03:32