I'm trying to make/train a twitter sentiment analyser in ipython notebook and am having serious problems with one section of code:
import csv
#Read the tweets one by one and process it
inpTweets = csv.reader(open('SampleTweets.csv', 'rb'), delimiter=',', quotechar='|')
tweets = []
for row in inpTweets:
sentiment = row[0]
tweet = row[1]
processedTweet = processTweet(tweet)
featureVector = getFeatureVector(processedTweet, stopwords)
tweets.append((featureVector, sentiment));
#end loop
And I'm getting this error:
TypeError Traceback (most recent call last)
<ipython-input-10-bbcb1b9f05f4> in <module>()
7 sentiment = row[0]
8 tweet = row[1]
----> 9 processedTweet = processTweet(tweet)
10 featureVector = getFeatureVector(processedTweet, stopwords)
11 tweets.append((featureVector, sentiment));
TypeError: 'str' object is not callable
And help would be seriously great, thanks!
Here your processedTweet should be a str hence you can't call it.
Example -
>>> a = 'apple'
>>> a(0)
Traceback (most recent call last):
File "<pyshell#212>", line 1, in <module>
a(0)
TypeError: 'str' object is not callable
But when I use index, it's fine. Callable means you are using that as a function like sum etc.
>>> a[0]
'a'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With