I have the following text file that has these lists :
['2009-06-12 14:19:28 ', '0']
['2009-06-13 00:58:10 ', '0']
['2009-06-13 01:00:25 ', '0']
['2009-06-15 03:24:23 ', '0']
['2009-06-25 17:50:46 ', '0']
['2009-06-29 20:54:52 ', '0']
['2009-06-30 20:31:19 ', '0']
['2009-07-09 03:01:25 ', '0']
['2009-07-12 14:45:53 ', '0']
['2009-07-12 15:09:38 ', '0']
The second element is an integer, however, the first element is a string. I need the first element of each lis to be a date instead of string?
I tried this code:
word[0]=datetime.strptime(word[0],'%Y/%m/%d %H:%M:%S')
but I get this error:
ValueError: time data '2009-04-02 22:50:06 ' does not match format '%Y/%m/%d %H:%M:%S'
the current code I have that cleans the data is the following:
with open('newdata.txt') as f:
for line in f:
tweet=re.sub(r'T\t',"",line)
t=re.sub(r'W\t',"\/\/",tweet)
data=t.split("\/\/")
sentiment_value= s.sentiment(data[1])
data.append(sentiment_value)
words = [w.replace('pos', '1') for w in data]
word=[w.replace('neg','0')for w in words]
del word[1]
print(word)
What I have tried:
I tried this code:
word[0]=datetime.strptime(word[0].strip(),'%Y/%m/%d %H:%M:%S')
but I get this error:
ValueError: time data '2009-04-02 22:50:06 ' does not match format '%Y/%m/%d %H:%M:%S'