2

I have df:

ID,"address","used_at","active_seconds","pageviews"
71ecd2aa165114e5ee292131f1167d8c,"auto.drom.ru",2014-05-17 10:58:59,166,2
71ecd2aa165114e5ee292131f1167d8c,"auto.drom.ru",2016-07-17 17:34:07,92,4
70150aba267f671045f147767251d169,"avito.ru/*/avtomobili",2014-06-15 11:52:09,837,40
bc779f542049bcabb9e68518a215814e,"auto.yandex.ru",2014-01-16 22:23:56,8,1
bc779f542049bcabb9e68518a215814e,"avito.ru/*/avtomobili",2014-01-18 14:38:33,313,5
bc779f542049bcabb9e68518a215814e,"avito.ru/*/avtomobili",2016-07-18 18:12:07,20,1

I need to delete all strings where used_at more than 2016-06-30. How can I do that?

1 Answer 1

4

Use dt.date with boolean indexing:

print (df.used_at.dt.date > pd.to_datetime('2016-06-30').date())
0    False
1     True
2    False
3    False
4    False
5     True
Name: used_at, dtype: bool

print (df[df.used_at.dt.date > pd.to_datetime('2016-06-30').date()])
                                 ID                address  \
1  71ecd2aa165114e5ee292131f1167d8c           auto.drom.ru   
5  bc779f542049bcabb9e68518a215814e  avito.ru/*/avtomobili   

              used_at  active_seconds  pageviews  
1 2016-07-17 17:34:07              92          4  
5 2016-07-18 18:12:07              20          1  

Or you can define datetime by year, month and day:

print (df[df.used_at.dt.date > pd.datetime(2016, 6, 30).date()])
                                 ID                address  \
1  71ecd2aa165114e5ee292131f1167d8c           auto.drom.ru   
5  bc779f542049bcabb9e68518a215814e  avito.ru/*/avtomobili   

              used_at  active_seconds  pageviews  
1 2016-07-17 17:34:07              92          4  
5 2016-07-18 18:12:07              20          1  
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.