☆☆ 新着記事 ☆☆

2019年4月27日土曜日

Tweepy Methodで取得できるデータとpandas メモ

Pandasのデータフレームにするのは、直観的に分かります。

extractor = twitter_setup()
tweets = extractor.user_timeline(screen_name="realDonaldTrump", count=5)

print("Number of tweets extracted: {}.\n".format(len(tweets)))

for tweet in tweets:
    print(tweet.text,tweet.favorite)

tweet_text = pd.DataFrame(data=[(tweet.text,tweet.favorite) for tweet in tweets],columns=['Twwet','Likes'])
print(tweet_text)

(output)

Number of tweets extracted: 5.

THANK YOU @NRA! #NRAAM https://t.co/SWkpe1eFhT 27513
“U.S. Economy Grows 3.2% in Q1, Smashing Expectations” https://t.co/HltPdlkOD0 39206
RT @WhiteHouse: "With God as our witness, we swear today that we will defend our rights, we wil
l safeguard our freedoms, we will uphold our… 0
RT @WhiteHouse: “Under my Administration, we will never surrender American sovereignty to anyo
ne. We will never allow foreign bureaucrats t… 0
Spoke to Saudi Arabia and others about increasing oil flow. All are in agreement. The Californi
a tax on gasoline is… https://t.co/znQjuoNReT 46372

                                               Twwet  Likes
0     THANK YOU @NRA! #NRAAM https://t.co/SWkpe1eFhT  27513
1  “U.S. Economy Grows 3.2% in Q1, Smashing Expec...  39206
2  RT @WhiteHouse: "With God as our witness, we s...      0
3  RT @WhiteHouse: “Under my Administration, we w...      0
4  Spoke to Saudi Arabia and others about increas...  46372


(参考)
JSON形式に
#for tweet in tw.Cursor(extractor.search, q='Trump').items(5):
#    tweets.append(tweet._json)

0 件のコメント:

コメントを投稿