I am trying to filter out columns in a pandas frame based on whether they have type date or not. I can figure out which ones, but then I have to parse this output or manually select the columns. I want to automatically select date columns. Here is what I have as an example - I would only like to select the "date_col" column in this case.
import pandas as pd df = pd.DataFrame([['Feb-2017', 1, 2], ['Mar-2017', 1, 2], ['Apr-2017', 1, 2], ['May-2017', 1, 2]], columns=['date_str', 'col1', 'col2']) df['date_col'] = pd.to_datetime(df['date_str']) df.dtypes
Of:
date_str object col1 int64 col2 int64 date_col datetime64[ns] dtype: object
python numpy pandas dataframe
Charlie haley
source share