我试图了解如何将csv逻辑应用于脚本中已经存在的数据帧输出。
对csv的情感分析
cellForRowAtIndexPath
我有一个数据框,其中有4列,其中一列有成绩单
import pandas as pd
import csv
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
with open('After.csv',"r",errors='ignore') as f:
reader = csv.reader(f)
your_list = list(reader)
analyser = SentimentIntensityAnalyzer()
def print_sentiment_scores(alist):
for aSentence in alist:
asnt = analyser.polarity_scores(aSentence[0])
print(str(asnt))
df_before = print_sentiment_scores(your_list)
print_sentiment_scores(your_list)
def print_sentiment_scores(alist):
polarity_scores = []
for aSentence in alist:
asnt = analyser.polarity_scores(aSentence[0])
print(str(asnt))
polarity_scores += [asnt]
return polarity_scores
output_df = pd.DataFrame(print_sentiment_scores(your_list))
output_df.to_csv('some_name.csv')
[353行x 5列]
test3
Out[52]:
confidence ... speaker
0 0.86 ... 0
1 0.91 ... 0
2 0.94 ... 0
3 0.86 ... 0
4 0.99 ... 0
如何将我上面的情感分析脚本应用于test3数据框中的此特定列(笔录)?