我对来自 Twitter 的几条推文进行了情绪分析。我在 for 循环中做了这个并得到了我需要的结果。下一步是将其放入DataFrame。我正在尝试将 for 循环放入 DataFrame 中。这是for循环:
x = 1
for tweet in public_tweets:
print(x)
print(tweet.text)
analysis = TextBlob(tweet.text)
print(analysis.sentiment)
x= x+1
我想要两列,分别称为“推文”和“情绪”。谁能帮我吗?
谢谢!
这可能会有所帮助。
import pandas as pd
x = 1
d = {} #Create a dict with tweet and sentiment
for tweet in public_tweets:
analysis = TextBlob(tweet.text)
print(analysis.sentiment)
x= x+1
d[tweet.text] = analysis.sentiment
c = ['Tweets','Sentiment']
df = pd.DataFrame(list(d.items()), columns=c) #form a DF.
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句