Update app.py
Browse files
app.py
CHANGED
|
@@ -19,11 +19,16 @@ def load_and_clean_data():
|
|
| 19 |
|
| 20 |
# Concatenate dataframes and clean data
|
| 21 |
df_combined = pd.concat([df1, df2, df3, df4])
|
|
|
|
|
|
|
| 22 |
df_combined['Domain'] = df_combined['Domain'].replace({"MUSLIM": "Muslim", "nan": pd.NA, "None": pd.NA, "Other-Ethnic": "Other-Ethnicity"})
|
|
|
|
|
|
|
| 23 |
df_combined['Sentiment'] = df_combined['Sentiment'].replace({"nan": pd.NA, "None": pd.NA, "No": pd.NA})
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
| 27 |
|
| 28 |
return df_combined
|
| 29 |
|
|
@@ -129,11 +134,10 @@ def create_top_discriminatory_domains_chart(df):
|
|
| 129 |
return fig
|
| 130 |
|
| 131 |
# Function for Channel-wise Sentiment Over Time Chart
|
| 132 |
-
def
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
fig
|
| 136 |
-
fig.update_layout(title='Channel-wise Sentiment Over Time', margin=dict(l=20, r=20, t=40, b=20))
|
| 137 |
return fig
|
| 138 |
|
| 139 |
# Function for Channel-wise Distribution of Discriminative Content Chart
|
|
@@ -183,7 +187,7 @@ def render_dashboard(page, df_filtered):
|
|
| 183 |
st.title("Channel Analysis Dashboard")
|
| 184 |
col1, col2 = st.columns(2)
|
| 185 |
with col1:
|
| 186 |
-
st.plotly_chart(
|
| 187 |
with col2:
|
| 188 |
st.plotly_chart(create_channel_discrimination_chart(df_filtered))
|
| 189 |
|
|
|
|
| 19 |
|
| 20 |
# Concatenate dataframes and clean data
|
| 21 |
df_combined = pd.concat([df1, df2, df3, df4])
|
| 22 |
+
|
| 23 |
+
# Replace 'nan' and 'None' with numpy NaN for removal
|
| 24 |
df_combined['Domain'] = df_combined['Domain'].replace({"MUSLIM": "Muslim", "nan": pd.NA, "None": pd.NA, "Other-Ethnic": "Other-Ethnicity"})
|
| 25 |
+
|
| 26 |
+
# Specific replacements for 'Sentiment' and 'Discrimination'
|
| 27 |
df_combined['Sentiment'] = df_combined['Sentiment'].replace({"nan": pd.NA, "None": pd.NA, "No": pd.NA})
|
| 28 |
+
df_combined['Discrimination'] = df_combined['Discrimination'].replace({"nan": pd.NA, "None": pd.NA, "No": pd.NA})
|
| 29 |
+
|
| 30 |
+
# Drop rows with NA values in 'Domain', 'Sentiment', and 'Discrimination'
|
| 31 |
+
df_combined.dropna(subset=['Domain', 'Sentiment', 'Discrimination'], inplace=True)
|
| 32 |
|
| 33 |
return df_combined
|
| 34 |
|
|
|
|
| 134 |
return fig
|
| 135 |
|
| 136 |
# Function for Channel-wise Sentiment Over Time Chart
|
| 137 |
+
def create_sentiment_distribution_by_channel_chart(df):
|
| 138 |
+
sentiment_by_channel = df.groupby(['Channel', 'Sentiment']).size().reset_index(name='counts')
|
| 139 |
+
fig = px.bar(sentiment_by_channel, x='Channel', y='counts', color='Sentiment', title="Sentiment Distribution by Channel", barmode='group')
|
| 140 |
+
fig.update_layout(margin=dict(l=20, r=20, t=40, b=20), xaxis_title="Channel", yaxis_title="Counts", font=dict(size=12))
|
|
|
|
| 141 |
return fig
|
| 142 |
|
| 143 |
# Function for Channel-wise Distribution of Discriminative Content Chart
|
|
|
|
| 187 |
st.title("Channel Analysis Dashboard")
|
| 188 |
col1, col2 = st.columns(2)
|
| 189 |
with col1:
|
| 190 |
+
st.plotly_chart(create_sentiment_distribution_by_channel_chart(df_filtered))
|
| 191 |
with col2:
|
| 192 |
st.plotly_chart(create_channel_discrimination_chart(df_filtered))
|
| 193 |
|