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
| labels = ['Negative_Trump', 'Negative_Biden'] | |
| sizes = lis_neg | |
| explode = (0.1, 0.1) | |
| fig1, ax1 = plt.subplots() | |
| ax1.pie(sizes, explode=explode, labels = labels, autopct = '%1.1f%%', shadow = True, startangle=90) | |
| ax1.set_title('Negative tweets on both the handles') | |
| plt.show() |
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
| # Start with one review: | |
| text = str(df_subset_biden.text) | |
| # Create and generate a word cloud image: | |
| wordcloud = WordCloud(max_font_size=100, max_words=500,scale=10,relative_scaling=.6,background_color="black", colormap = "rainbow").generate(text) | |
| # Display the generated image: | |
| plt.figure(figsize=(15,10)) | |
| plt.imshow(wordcloud, interpolation='bilinear') | |
| plt.axis("off") | |
| plt.show() |
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
| # Start with one review: | |
| text = str(df_subset_trump.text) | |
| # Create and generate a word cloud image: | |
| wordcloud = WordCloud(max_font_size=100, max_words=500, scale=10, relative_scaling=.6, background_color="black", colormap = "rainbow").generate(text) | |
| # Display the generated image: | |
| plt.figure(figsize=(15,10)) | |
| plt.imshow(wordcloud, interpolation='bilinear') | |
| plt.axis("off") | |
| plt.show() |
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
| most_negative2 = df_subset_biden[df_subset_biden.Sentiment_Polarity == -1].text.head() | |
| neg_txt2 = list(most_negative2) | |
| neg2 = df_subset_biden[df_subset_biden.Sentiment_Polarity == -1].Sentiment_Polarity.head() | |
| neg_pol2 = list(neg2) | |
| fig = go.Figure(data=[go.Table(columnorder = [1,2], | |
| columnwidth = [50,400], | |
| header=dict(values=['Polarity','Most Negative Replies on Biden\'s handle'], | |
| fill_color='paleturquoise', | |
| align='left'), |
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
| most_positive2 = df_subset_biden[df_subset_biden.Sentiment_Polarity == 1].text.tail() | |
| pos_txt2 = list(most_positive2) | |
| pos2 = df_subset_biden[df_subset_biden.Sentiment_Polarity == 1].Sentiment_Polarity.tail() | |
| pos_pol2 = list(pos2) | |
| fig = go.Figure(data=[go.Table(columnorder = [1,2], | |
| columnwidth = [50,400], | |
| header=dict(values=['Polarity','Most Positive Replies on Biden\'s handle'], | |
| fill_color='paleturquoise', | |
| align='left'), |
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
| most_negative1 = df_subset_trump[df_subset_trump.Sentiment_Polarity == -1].text.head() | |
| neg_txt1 = list(most_negative1) | |
| neg1 = df_subset_trump[df_subset_trump.Sentiment_Polarity == -1].Sentiment_Polarity.head() | |
| neg_pol1 = list(neg1) | |
| fig = go.Figure(data=[go.Table(columnorder = [1,2], | |
| columnwidth = [50,400], | |
| header=dict(values=['Polarity','Most Negative Replies on Trump\'s handle'], | |
| fill_color='paleturquoise', | |
| align='left'), |
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
| most_positive1 = df_subset_trump[df_subset_trump.Sentiment_Polarity == 1].text.head() | |
| pos_txt1 = list(most_positive1) | |
| pos1 = df_subset_trump[df_subset_trump.Sentiment_Polarity == 1].Sentiment_Polarity.head() | |
| pos_pol1 = list(pos1) | |
| fig = go.Figure(data=[go.Table(columnorder = [1,2], | |
| columnwidth = [50,400], | |
| header=dict(values=['Polarity','Most Positive Replies on Trump\'s Handle'], | |
| fill_color='paleturquoise', | |
| align='left'), |
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
| Politicians = ['Donald Trump', 'Joe Biden'] | |
| lis_pos = [positive_per1, positive_per2] | |
| lis_neg = [negative_per1, negative_per2] | |
| fig = go.Figure(data=[ | |
| go.Bar(name='Positive', x=Politicians, y=lis_pos), | |
| go.Bar(name='Negative', x=Politicians, y=lis_neg) | |
| ]) | |
| # Change the bar mode | |
| fig.update_layout(barmode='group') |
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
| # Let's make both the datasets balanced now. So we will just take 1000 rows from both datasets and drop rest of them. | |
| # Donald Trump | |
| np.random.seed(10) | |
| remove_n =324 | |
| drop_indices = np.random.choice(Trump_reviews.index, remove_n, replace=False) | |
| df_subset_trump = Trump_reviews.drop(drop_indices) | |
| df_subset_trump.shape | |
| # Joe Biden |
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
| new2 = Biden_reviews.groupby('Expression Label').count() | |
| x = list(new2['Sentiment_Polarity']) | |
| y = list(new2.index) | |
| tuple_list = list(zip(x,y)) | |
| df = pd.DataFrame(tuple_list, columns=['x','y']) | |
| df['color'] = 'blue' | |
| df['color'][1] = 'red' | |
| df['color'][2] = 'green' |