menikev commited on
Commit
848f63d
1 Parent(s): 72c555f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -6
app.py CHANGED
@@ -84,11 +84,22 @@ def create_sentiment_distribution_chart(df):
84
 
85
  # Visualization for Correlation between Sentiment and Discrimination
86
  def create_sentiment_discrimination_grouped_chart(df):
87
- crosstab_df = pd.crosstab(df['Sentiment'], df['Discrimination']).reset_index()
88
- melted_df = pd.melt(crosstab_df, id_vars='Sentiment', value_vars=['Yes', 'No'], var_name='Discrimination', value_name='Count')
89
- fig = px.bar(melted_df, x='Sentiment', y='Count', color='Discrimination', barmode='group', title="Sentiment vs. Discrimination")
90
- fig.update_layout(margin=dict(l=20, r=20, t=40, b=20), xaxis_title="Sentiment", yaxis_title="Count", font=dict(size=12))
91
- return fig
 
 
 
 
 
 
 
 
 
 
 
92
 
93
  # Function for Top Domains with Negative Sentiment Chart
94
  def create_top_negative_sentiment_domains_chart(df):
@@ -161,7 +172,11 @@ def render_dashboard(page, df_filtered):
161
  with col3:
162
  st.plotly_chart(create_sentiment_distribution_chart(df_filtered))
163
  with col4:
164
- st.plotly_chart(create_sentiment_discrimination_grouped_chart(df_filtered))
 
 
 
 
165
 
166
  elif page == "Sentiment Analysis":
167
  st.title("Sentiment Analysis Dashboard")
@@ -191,5 +206,6 @@ def render_dashboard(page, df_filtered):
191
  with col2:
192
  st.plotly_chart(create_channel_discrimination_chart(df_filtered))
193
 
 
194
  # Render the selected dashboard page
195
  render_dashboard(page, df_filtered)
 
84
 
85
  # Visualization for Correlation between Sentiment and Discrimination
86
  def create_sentiment_discrimination_grouped_chart(df):
87
+ # Creating a crosstab of 'Sentiment' and 'Discrimination'
88
+ crosstab_df = pd.crosstab(df['Sentiment'], df['Discrimination'])
89
+
90
+ # Check if 'Yes' and 'No' are in the columns after the crosstab operation
91
+ value_vars = crosstab_df.columns.intersection(['Yes', 'No']).tolist()
92
+
93
+ # If 'No' is not in columns, it will not be included in melting
94
+ melted_df = pd.melt(crosstab_df.reset_index(), id_vars='Sentiment', value_vars=value_vars, var_name='Discrimination', value_name='Count')
95
+
96
+ # Proceeding to plot only if we have data to plot
97
+ if not melted_df.empty:
98
+ fig = px.bar(melted_df, x='Sentiment', y='Count', color='Discrimination', barmode='group', title="Sentiment vs. Discrimination")
99
+ fig.update_layout(margin=dict(l=20, r=20, t=40, b=20), xaxis_title="Sentiment", yaxis_title="Count", font=dict(size=12))
100
+ return fig
101
+ else:
102
+ return "No data to display for the selected filters."
103
 
104
  # Function for Top Domains with Negative Sentiment Chart
105
  def create_top_negative_sentiment_domains_chart(df):
 
172
  with col3:
173
  st.plotly_chart(create_sentiment_distribution_chart(df_filtered))
174
  with col4:
175
+ chart = create_sentiment_discrimination_grouped_chart(df_filtered)
176
+ if isinstance(chart, str):
177
+ st.write(chart)
178
+ else:
179
+ st.plotly_chart(chart)
180
 
181
  elif page == "Sentiment Analysis":
182
  st.title("Sentiment Analysis Dashboard")
 
206
  with col2:
207
  st.plotly_chart(create_channel_discrimination_chart(df_filtered))
208
 
209
+
210
  # Render the selected dashboard page
211
  render_dashboard(page, df_filtered)