我有一个脚本,它搜索Twitter中的某个术语,然后输出一些返回结果的属性。尝试向numpy数组添加内容
我想只是一个空白数组返回。任何想法为什么?
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的:)
坚持列表附加在循环中。它更快,更容易。 – hpaulj