Monday, April 1, 2019

NLP in Python

NLP in Python


#importing tweeter library and textblob

import tweepy from textblob import TextBlob


#making connection with twitter

consumer_key='vBsuS1MZU1HZkcEZCF1X3RcN1' consumer_secret='BlK6sqtAxPrDWcohheZ3WleCsdzV68oilt6sHM122FfrU5gDj9' access_token='2840514410-tvwxQYYIk3WBBpALt2EnPJiSiro6oQjEk6HHPrt' access_token_secret='AdgQONrI4VpM88g6g2AZvlVAlGNwteSOYh0lBZ6Q8rd45' auth=tweepy.OAuthHandler(consumer_key,consumer_secret) auth.set_access_token(access_token,access_token_secret) api=tweepy.API(auth) public_tweets=api.search('Trump') text_list=[] sentiment_list=[] for tweet in public_tweets: text_list.append(tweet.text) print(tweet.text) analysis=TextBlob(tweet.text) print(analysis.sentiment) sentiment_list.append(analysis.sentiment)


#Saving Result in CSV

import csv
with open('text.csv','w') as f:
    writer=csv.writer(f,delimiter='\t')
    writer.writerows(zip(text_list,sentiment_list))



    

No comments:

Post a Comment

JOB in 2019

Automated - Digital One o One Meetings- An Idea

                                            Automated - Digital One o One Discussion                                                       ...