使用模式库时python列表索引超出范围
我正在计算情绪分数,我使用模式库来计算。我基本上是从一个csv文件中读取的,该文件只有第一列中的文本数据。不知怎的,我一直犯这样的错误:使用模式库时python列表索引超出范围,python,list,Python,List,我正在计算情绪分数,我使用模式库来计算。我基本上是从一个csv文件中读取的,该文件只有第一列中的文本数据。不知怎的,我一直犯这样的错误: sentiment_score_list.append(round(sentiment(item[0])[0],1)) IndexError: list index out of range 这是我的密码: cr = csv.reader(open(sys.argv[1],"rU").readlines()[1:]) text_data=[]
sentiment_score_list.append(round(sentiment(item[0])[0],1))
IndexError: list index out of range
这是我的密码:
cr = csv.reader(open(sys.argv[1],"rU").readlines()[1:])
text_data=[]
for row in cr:
text_data.append(row)
# print row
#first col is text
#populate the sentiment score list with just the sentiment score
sentiment_score_list=[]
for item in text_data:
sentiment_score_list.append(round(sentiment(item[0])[0],1))
print round(sentiment(item[0])[0],1)
对于项的某些值,项或项[0]都是空列表
如果示例代码已完成,则有时可能返回一个空列表。是的,csv文件中有一个空行。