thak123 commited on
Commit
6d0c5b3
1 Parent(s): dbb85c7

Update index.py

Browse files
Files changed (1) hide show
  1. index.py +8 -6
index.py CHANGED
@@ -247,9 +247,10 @@ def update_output(selected_topic, selected_domain, start_date, end_date):
247
  bar_fig_1.update_xaxes(tickformat="%b %d<br>%Y")
248
  # Bar Graph ends
249
 
 
250
  # filter dataframes based on updated data range
251
  # Filtering data...
252
- df_filtered = counts[(counts['Topic'] == selected_topic) &
253
  (counts['domain_folder_name'] == selected_domain) &
254
  (counts['date'] >= start_date) &
255
  (counts['date'] <= end_date)]
@@ -266,7 +267,7 @@ def update_output(selected_topic, selected_domain, start_date, end_date):
266
  df_all_combinations = pd.DataFrame(index=all_combinations).reset_index()
267
 
268
  # Merge filtered DataFrame with DataFrame of all combinations
269
- merged_df = pd.merge(df_all_combinations, df_filtered, on=['FinBERT_label', 'Topic', 'domain_folder_name', 'date'], how='left')
270
 
271
  # Fill missing values with zeros
272
  merged_df['count'].fillna(0, inplace=True)
@@ -281,6 +282,7 @@ def update_output(selected_topic, selected_domain, start_date, end_date):
281
  # Update layout...
282
  line_fig_2.update_layout(xaxis_title='Date', yaxis_title='Number of News Articles',
283
  xaxis=dict(tickformat="%b %d<br>%Y"))
 
284
 
285
  # Map original labels to their translated versions
286
  label_translation = {'positive': 'positivo', 'neutral': 'neutro', 'negative': 'negativo'}
@@ -307,7 +309,7 @@ def update_output(selected_topic, selected_domain, start_date, end_date):
307
  label_colors = {'positivo': '#039a4d', 'neutro': '#3c03f4', 'negativo': '#ca3919'}
308
 
309
  # Filter DataFrame for current media category
310
- media_df = df_filtered[df_filtered['Veículos de notícias'] == media]
311
 
312
  # Group by FinBERT_label and count occurrences
313
  label_counts = media_df['FinBERT_label_transformed'].value_counts()
@@ -331,9 +333,9 @@ def update_output(selected_topic, selected_domain, start_date, end_date):
331
  ordered=True)
332
 
333
  # Sort DataFrame by sentiment label and date
334
- df_filtered = df_filtered.sort_values(by=['FinBERT_label', 'date'])
335
-
336
- return line_fig_1, bar_fig_1, pie_chart_1, line_fig_2, pie_chart_2, df_filtered.to_dict('records')
337
  else:
338
  return {'data': []},{'data': []} ,{'data': []} ,{'data': []} , {'data': []}, {'data': []}
339
 
 
247
  bar_fig_1.update_xaxes(tickformat="%b %d<br>%Y")
248
  # Bar Graph ends
249
 
250
+ # line-fig 2 starts
251
  # filter dataframes based on updated data range
252
  # Filtering data...
253
+ df_filtered_2 = counts[(counts['Topic'] == selected_topic) &
254
  (counts['domain_folder_name'] == selected_domain) &
255
  (counts['date'] >= start_date) &
256
  (counts['date'] <= end_date)]
 
267
  df_all_combinations = pd.DataFrame(index=all_combinations).reset_index()
268
 
269
  # Merge filtered DataFrame with DataFrame of all combinations
270
+ merged_df = pd.merge(df_all_combinations, df_filtered_2, on=['FinBERT_label', 'Topic', 'domain_folder_name', 'date'], how='left')
271
 
272
  # Fill missing values with zeros
273
  merged_df['count'].fillna(0, inplace=True)
 
282
  # Update layout...
283
  line_fig_2.update_layout(xaxis_title='Date', yaxis_title='Number of News Articles',
284
  xaxis=dict(tickformat="%b %d<br>%Y"))
285
+ # line-fig 2 ends
286
 
287
  # Map original labels to their translated versions
288
  label_translation = {'positive': 'positivo', 'neutral': 'neutro', 'negative': 'negativo'}
 
309
  label_colors = {'positivo': '#039a4d', 'neutro': '#3c03f4', 'negativo': '#ca3919'}
310
 
311
  # Filter DataFrame for current media category
312
+ media_df = df_filtered[df_filtered['Veículos de notícias'] == selected_domain]
313
 
314
  # Group by FinBERT_label and count occurrences
315
  label_counts = media_df['FinBERT_label_transformed'].value_counts()
 
333
  ordered=True)
334
 
335
  # Sort DataFrame by sentiment label and date
336
+ # df_filtered = df_filtered.sort_values(by=['FinBERT_label', 'date'])
337
+ # df_filtered.to_dict('records')
338
+ return line_fig_1, bar_fig_1, pie_chart_1, line_fig_2, pie_chart_2, {'data': []}
339
  else:
340
  return {'data': []},{'data': []} ,{'data': []} ,{'data': []} , {'data': []}, {'data': []}
341