Created
October 4, 2018 13:01
-
-
Save DFoly/33c3546192a741119bb7ba44f2c69f34 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if __name__ == '__main__': | |
| t = TweetObject( host = 'localhost', database = 'twitterdb', user = 'root') | |
| data = t.MySQLConnect("SELECT created_at, tweet FROM `TwitterDB`.`Golf`;") | |
| data = t.clean_tweets(data) | |
| data['Sentiment'] = np.array([t.sentiment(x) for x in data['clean_tweets']]) | |
| t.word_cloud(data) | |
| t.save_to_csv(data) | |
| pos_tweets = [tweet for index, tweet in enumerate(data["clean_tweets"]) if data["Sentiment"][index] > 0] | |
| neg_tweets = [tweet for index, tweet in enumerate(data["clean_tweets"]) if data["Sentiment"][index] < 0] | |
| neu_tweets = [tweet for index, tweet in enumerate(data["clean_tweets"]) if data["Sentiment"][index] == 0] | |
| #Print results | |
| print("percentage of positive tweets: {}%".format(100*(len(pos_tweets)/len(data['clean_tweets'])))) | |
| print("percentage of negative tweets: {}%".format(100*(len(neg_tweets)/len(data['clean_tweets'])))) | |
| print("percentage of neutral tweets: {}%".format(100*(len(neu_tweets)/len(data['clean_tweets'])))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment