Q:

Remove columns with a date and time stamp Python

The CSV I am working has a column that is named "First Detected" and has data that looks like this "2/13/2016 23:04".  I am trying to use pandas to delete the columns that do not match a date I enter, I also want it to not care about what the time stamp is.  For instance I want to keep the rows with the date 4/12/2016 and delete the rest.  How can this be done with Pandas? 

A:

You can use boolean indexing with to_datetime:
date = '4/12/2016'
df = pd. DataFrame({'First Detected':['2/13/2016 23:04','2/13/2016 23:04','4/12/2016 23:04']})
print (df)

    First Detected
0  2/13/2016 23:04
1  2/13/2016 23:04
2  4/12/2016 23:04

df['First Detected'] = pd.to_datetime(df['First Detected'])

df = df[df['First Detected'].dt.date == pd.to_datetime(date).date()]
print (df)
       First Detected
2 2016-04-12 23:04:00

