Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Code:-

df = pd.DataFrame({'col1':t, 'col2':wordList})
df.columns=['DNT','tweets']
df.DNT = pd.to_datetime(df.DNT, errors='coerce')
check=df[ (df.DNT < '09:20:00') & (df.DNT > '09:00:00') ]

Don't know why this code is not working. Does anyone know what is wrong in the above code?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
162 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can compare with datetime format like this:

Suppose:

import pandas as pd
import datetime
df = pd.DataFrame({'col1':['2017-05-24 09:06:11','2017-05-24 09:06:12','2017-05-24 09:00:00'], 'col2':['hello','hi','bonjour']})
df.columns=['DNT','tweets']
df.DNT = pd.to_datetime(df.DNT, errors='coerce')
df

df will be:

    DNT                  tweets
0   2017-05-24 09:06:11  hello
1   2017-05-24 09:06:12  hi
2   2017-05-24 09:00:00  bonjour

Then you can compare with start and end:

end = datetime.datetime(2017, 5, 24, 9, 20) #2017-05-24 09:20:00
start = datetime.datetime(2017, 5, 24, 9) #2017-05-24 09:00:00
df[ (df.DNT < end) & (df.DNT > start) ]

Then filter result will be:

    DNT                  tweets
0   2017-05-24 09:06:11  hello
1   2017-05-24 09:06:12  hi

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...