Akshayram1 commited on
Commit
eb055f8
·
verified ·
1 Parent(s): 461696a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -88,22 +88,27 @@ def score_news(parsed_news_df):
88
 
89
 
90
  def plot_hourly_sentiment(parsed_and_scored_news, ticker):
91
-
 
 
92
  # Group by date and ticker columns from scored_news and calculate the mean
93
- mean_scores = parsed_and_scored_news.resample('H').mean()
94
 
95
- # Plot a bar chart with plotly
96
- fig = px.bar(mean_scores, x=mean_scores.index, y='sentiment_score', title = ticker + ' Hourly Sentiment Scores')
97
- return fig # instead of using fig.show(), we return fig and turn it into a graphjson object for displaying in web page later
98
 
99
  def plot_daily_sentiment(parsed_and_scored_news, ticker):
100
-
 
 
101
  # Group by date and ticker columns from scored_news and calculate the mean
102
- mean_scores = parsed_and_scored_news.resample('D').mean()
 
 
 
 
103
 
104
- # Plot a bar chart with plotly
105
- fig = px.bar(mean_scores, x=mean_scores.index, y='sentiment_score', title = ticker + ' Daily Sentiment Scores')
106
- return fig # instead of using fig.show(), we return fig and turn it into a graphjson object for displaying in web page later
107
 
108
  # for extracting data from finviz
109
  finviz_url = 'https://finviz.com/quote.ashx?t='
 
88
 
89
 
90
  def plot_hourly_sentiment(parsed_and_scored_news, ticker):
91
+ # Ensure that only numeric columns are resampled
92
+ numeric_cols = parsed_and_scored_news.select_dtypes(include=['float64', 'int64'])
93
+
94
  # Group by date and ticker columns from scored_news and calculate the mean
95
+ mean_scores = numeric_cols.resample('h').mean()
96
 
97
+ # Plot a bar chart with Plotly
98
+ fig = px.bar(mean_scores, x=mean_scores.index, y='sentiment_score', title=ticker + ' Hourly Sentiment Scores')
99
+ return fig # Return the figure to display in the Streamlit app
100
 
101
  def plot_daily_sentiment(parsed_and_scored_news, ticker):
102
+ # Ensure that only numeric columns are resampled
103
+ numeric_cols = parsed_and_scored_news.select_dtypes(include=['float64', 'int64'])
104
+
105
  # Group by date and ticker columns from scored_news and calculate the mean
106
+ mean_scores = numeric_cols.resample('D').mean()
107
+
108
+ # Plot a bar chart with Plotly
109
+ fig = px.bar(mean_scores, x=mean_scores.index, y='sentiment_score', title=ticker + ' Daily Sentiment Scores')
110
+ return fig # Return the figure to display in the Streamlit app
111
 
 
 
 
112
 
113
  # for extracting data from finviz
114
  finviz_url = 'https://finviz.com/quote.ashx?t='