How do I generate a new column on Pandas with Python to Generate Tweet Hyperlinks with Conversation ID

Viewed 27

I am using Tweepy to scrape tweets. I cannot get the tweet URL using tweepy but I can get the conversation ID. I want to generate a new column that is essentially twitter.com/user/status/(conversation_id) of every cell before saving it.

How can I do this? My current code after the scraping cursor is:

columns = ['conservation id',
           'created_at', 
           'likes', 
           'full_text', 
           'retweet count', 
           'user location', 
           'user name', 
           'user verified', 
           'in reply to status?', 
           'language']
data = []

for tweet in tweets:
    data.append([tweet.id_str, 
                 tweet.created_at, 
                 tweet.favorite_count, 
                 tweet.full_text, 
                 tweet.retweet_count, 
                 tweet.user.location, 
                 tweet.user.screen_name, 
                 tweet.user.verified, 
                 tweet.in_reply_to_status_id, 
                 tweet.lang])

df = pd.DataFrame(data, columns=columns)

print(df)

df.to_csv('testrun.csv')
1 Answers

Fixed it.

for tweet in tweets:
    data.append([tweet.created_at, 
                 tweet.favorite_count, 
                 tweet.full_text, 
                 tweet.retweet_count, 
                 "https://twitter.com/user/status/"+tweet.id_str,
                 tweet.user.location, 
                 tweet.user.screen_name, 
                 tweet.user.verified, 
                 tweet.in_reply_to_status_id, 
                 tweet.lang])
Related