文の肯定と否定のスコアをテキストファイルに保存しようとしています。スコアをCSVファイルに保存したい。私は、下記のコードを実装しました:Python - CSVファイルに浮動小数点値を格納する
import openpyxl
from nltk.tokenize import sent_tokenize
import csv
from senti_classifier import senti_classifier
from nltk.corpus import wordnet
file_content = open('amazon_kindle.txt')
for lines in file_content:
sentence = sent_tokenize(lines)
pos_score,neg_score = senti_classifier.polarity_scores(sentence)
with open('target.csv','w') as f:
writer = csv.writer(f,lineterminator='\n',delimiter=',')
for val in range(pos_score):
writer.writerow(float(s) for s in val[0])
f.close()
をしかし、コードがfor
ループの中で私に次のエラーが表示されます。
あなたのコードとエラーが一致していない:
Traceback (most recent call last):
File "C:\Users\pc\AppData\Local\Programs\Python\Python36-32\classifier.py", line 21, in for val in pos_score: TypeError: 'float' object is not iterable
感謝:これも
with
ブロックであることをwriterow()
ニーズを意味し、 –