希望你能帮上忙
我有以下内容-我正在尝试确定csv中几个值的情绪。
这似乎可以一次一个地工作,但是当我尝试向我的pandas dataframe添加一个新列来存储它时,所有的值都是相同的。
有人知道我做错了什么吗?
In [22]: import pandas as pd
...: from textblob import TextBlob
...:
...: path = 'Desktop/sentiment.csv'
...: df = pd.read_csv(path, delimiter=',', header='infer')
...:
...: for row in df.iterrows():
...: blob = TextBlob(str(df.Text))
...: df['sentiment'] = blob.sentiment.polarity
...:
In [23]: df
Out[23]:
Text sentiment
0 I love this game, I think its great 0.107143
1 really buggy, not a good experience, do not buy 0.107143
2 not too bad, not too good 0.107143
In [24]: 发布于 2019-01-25 05:15:18
不使用iterrows,而使用以下命令:
df['sentiment'] = df.Text.apply(lambda x: TextBlob(str(x)).sentiment.polarity)https://stackoverflow.com/questions/54355066
复制相似问题