【发布时间】:2017-04-11 19:31:56
【问题描述】:
我有一个脚本,它在 Twitter 上搜索某个词,然后打印出返回结果的一些属性。
我正在尝试只返回一个空白数组。任何想法为什么?
public_tweets = api.search("Trump")
tweets_array = np.empty((0,3))
for tweet in public_tweets:
userid = api.get_user(tweet.user.id)
username = userid.screen_name
location = tweet.user.location
tweetText = tweet.text
analysis = TextBlob(tweet.text)
polarity = analysis.sentiment.polarity
np.append(tweets_array, [[username, location, tweetText]], axis=0)
print(tweets_array)
我试图实现的行为类似于..
array = []
array.append([item1, item2, item3])
array.append([item4,item5, item6])
array 现在是[item1, item2, item3],[item4, item5, item6]。
但是在 Numpy 中:)
【问题讨论】:
-
坚持在循环中追加列表。它更快、更容易。
标签: arrays loops numpy tweepy textblob