Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用模式库时python列表索引超出范围_Python_List - Fatal编程技术网

使用模式库时python列表索引超出范围

使用模式库时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=[]

我正在计算情绪分数,我使用模式库来计算。我基本上是从一个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=[]
    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文件中有一个空行。