Dawn17
Dawn17

Reputation: 8297

Filtering Pandas column with specific conditions?

I have a pandas dataframe that looks like

                 Start Time
0       2017-06-23 15:09:32
1       2017-05-25 18:19:03
2       2017-01-04 08:27:49
3       2017-03-06 13:49:38
4       2017-01-17 14:53:07
5       2017-06-26 09:01:20
6       2017-05-26 09:41:44
7       2017-01-21 14:28:38
8       2017-04-20 16:08:51

I want to filter out the ones with month == 06. So it would be the row 1 and 5. I know how to filter it out for column that has only few categories, but in this case, if it's a date, I need to parse the date and check the month. But I am not sure how to do it with pandas. Please help.

Upvotes: 0

Views: 56

Answers (1)

BENY
BENY

Reputation: 323226

Using

#df['Start Time']=pd.to_datetime(df['Start Time'])
df1=df[df['Start Time'].dt.month==6].copy()

Upvotes: 2

Related Questions