-1

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?

Vic13
  • 451
  • 1
  • 4
  • 16

1 Answers1

1

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
Tiny.D
  • 6,466
  • 2
  • 15
  • 20
  • glad it helps :), u need practice more, coding more, then u will rock it :) – Tiny.D May 26 '17 at 05:21
  • Hey @Tiny.D I want to convert the words into dense vectors so that I can use them in neural networks. Words(example) 'automotive', 'auto', 'ebc', 'greenstuff', '6000', 'series', 'supreme', 'truck', 'and', 'suv', 'brake', 'pads', 'dp61603' Could you please tell me how to do it? – Vic13 May 29 '17 at 06:19
  • you can split the sentence string with split(), it will return a list which contain all words. – Tiny.D May 29 '17 at 06:21
  • Actually I wanted to know how can I convert these words into vectors ? – Vic13 May 29 '17 at 06:26
  • ok, please raise a question with details (your requirement, your expected result, etc), then let me know. – Tiny.D May 29 '17 at 06:28
  • Here is the link for the question [link](https://stackoverflow.com/questions/44236021/converting-list-of-strings-into-vector-form) – Vic13 May 29 '17 at 06:39
  • you'd better know how to ask question, not like that, with example data input will be better. – Tiny.D May 29 '17 at 06:41
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/145342/discussion-between-tiny-d-and-vic13). – Tiny.D May 29 '17 at 06:42