百度api情感分析数据导出

client = AipNlp(APP_ID, API_KEY, SECRET_KEY)
 
def sentimentClassify():
    x = open('评价内容2.txt','r',encoding = 'utf-8').readlines()
    i = 1
    pp=[]
    np=[]
    con=[]
    sen=[]
    all={}
    for i in range(2):
        text = x[i]
        result = client.sentimentClassify(text);
        print(result)
        if "error_code" in result.keys():
            pp.append(" ")
            np.append(" ")
            con.append(" ")
            sen.append(" ")
            all['positive_prob'] = pp
            all['negative_prob'] = np
            all['confidence'] = con
            all['sentiment'] = sen
        else:
            data = result['items']
            items = data[0]
            positive_prob = items['positive_prob']
            pp.append(positive_prob)
            negative_prob = items['negative_prob']
            np.append(negative_prob)
            confidence = items['confidence']
 
            con.append(confidence)
            sentiment = items['sentiment']
            sen.append(sentiment)
            all['positive_prob'] = pp
            all['negative_prob'] = np
            all['confidence'] = con
            all['sentiment'] = sen
    return all
 
def add(ulist):
    csv_input = pd.read_csv('sentimentResult.csv', encoding='utf-8')
    pp = DataFrame(ulist['positive_prob'])
    csv_input["positive_prob"] = pp
    csv_input.to_csv('sentimentResult.csv', index=False, encoding='utf-8')
    np = DataFrame(ulist['negative_prob'])
    csv_input["negative_prob"] = np
    csv_input.to_csv('sentimentResult.csv', index=False, encoding='utf-8')
    con = DataFrame(ulist['confidence'])
    csv_input["confidence"] = con
    csv_input.to_csv('sentimentResult.csv', index=False, encoding='utf-8')
    sen = DataFrame(ulist['sentiment'])
    csv_input["sentiment"] = sen
    csv_input.to_csv('sentimentResult.csv', index=False, encoding='utf-8')

if __name__ == '__main__':
    ALL = sentimentClassify()
    add(ALL)

如图,在网上找来的代码实际使用后虽然可以输出,但是使用add方法时会报下面的错误,请问有大佬知道原因吗

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 以帮助更多的人 ^-^