Reputation: 39
I was trying this code, and I got the following error. Someone, please help me!!
#Read the tweets one by one and process it
import csv
inpTweets = csv.reader(str(open('tweets.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
IndexError Traceback (most recent call last)
<ipython-input-15-6eb83cd8111f> in <module>()
7 for row in inpTweets:
8 sentiment = row[0]
----> 9 tweet = row[1]
10 processedTweet = processTweet(tweet)
11 featureVector = getFeatureVector(processedTweet, stopWords)
IndexError: string index out of range
Please help...
Upvotes: 1
Views: 38
Reputation: 34
I think you have tried to convert the opened file to string without reading it line by line and using delimiters. https://docs.python.org/3.4/library/csv.html
with open('file.csv', 'rb') as csvfile:
data = csv.reader(csvfile, delimiter=',', quotechar='|')
for row in data:
print(row, end=',')
Upvotes: 1