Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -59,25 +59,15 @@ scores_df = calculate_combined_scores_for_stocks(sp500_list, sp500_averages)
|
|
59 |
scores_df_sorted = scores_df.sort_values(by='Combined Score', ascending=False)
|
60 |
|
61 |
# Layout for displaying overview and details
|
62 |
-
col1, col2 = st.columns([
|
63 |
-
|
64 |
-
def color_combined_score(value):
|
65 |
-
"""Colors the combined score cell based on its value."""
|
66 |
-
if value > 0:
|
67 |
-
color = 'green'
|
68 |
-
elif value < 0:
|
69 |
-
color = 'red'
|
70 |
-
else:
|
71 |
-
color = 'none'
|
72 |
-
return f'background-color: {color};'
|
73 |
-
|
74 |
|
75 |
with col1:
|
76 |
st.subheader("Stock Overview")
|
77 |
-
#
|
78 |
scores_df_sorted['Combined Score'] = pd.to_numeric(scores_df_sorted['Combined Score'], errors='coerce')
|
79 |
# Apply color based on 'Combined Score' value and display the DataFrame
|
80 |
-
|
|
|
81 |
|
82 |
with col2:
|
83 |
st.subheader("Stock Details")
|
@@ -86,16 +76,30 @@ with col2:
|
|
86 |
ticker_symbol = st.selectbox('Select a stock for details', options=sorted_tickers)
|
87 |
if ticker_symbol:
|
88 |
with st.spinner(f'Fetching data for {ticker_symbol}...'):
|
89 |
-
stock_data,
|
90 |
comparison, _ = compare_to_index(stock_data, sp500_averages)
|
91 |
|
92 |
# Display the company name and ticker symbol
|
93 |
-
st.write(f"**{
|
94 |
-
st.write(info.get('longBusinessSummary', 'Description not available.'))
|
95 |
|
96 |
-
# Display each financial ratio and
|
97 |
-
for ratio
|
98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
|
100 |
|
101 |
|
|
|
59 |
scores_df_sorted = scores_df.sort_values(by='Combined Score', ascending=False)
|
60 |
|
61 |
# Layout for displaying overview and details
|
62 |
+
col1, col2 = st.columns([3, 5]) # For example, this will give the first column 3/8 of the width
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
with col1:
|
65 |
st.subheader("Stock Overview")
|
66 |
+
# Make sure to convert 'Combined Score' to numeric if it's not already
|
67 |
scores_df_sorted['Combined Score'] = pd.to_numeric(scores_df_sorted['Combined Score'], errors='coerce')
|
68 |
# Apply color based on 'Combined Score' value and display the DataFrame
|
69 |
+
styled_scores_df = scores_df_sorted.style.applymap(color_combined_score, subset=['Combined Score'])
|
70 |
+
st.dataframe(styled_scores_df, height=600)
|
71 |
|
72 |
with col2:
|
73 |
st.subheader("Stock Details")
|
|
|
76 |
ticker_symbol = st.selectbox('Select a stock for details', options=sorted_tickers)
|
77 |
if ticker_symbol:
|
78 |
with st.spinner(f'Fetching data for {ticker_symbol}...'):
|
79 |
+
stock_data, _ = fetch_stock_data(ticker_symbol)
|
80 |
comparison, _ = compare_to_index(stock_data, sp500_averages)
|
81 |
|
82 |
# Display the company name and ticker symbol
|
83 |
+
st.write(f"**{ticker_symbol}**")
|
|
|
84 |
|
85 |
+
# Display each financial ratio, its value, and the S&P 500 average
|
86 |
+
for ratio in stock_data.keys():
|
87 |
+
value = stock_data[ratio]
|
88 |
+
average = sp500_averages.loc[ratio, 'Average'] if ratio in sp500_averages.index else 'N/A'
|
89 |
+
comparison_result = comparison[ratio] if ratio in comparison else 'N/A'
|
90 |
+
st.write(f"{ratio}: {value} (Your Ratio) | {average} (S&P 500 Avg) - {comparison_result}")
|
91 |
+
|
92 |
+
# Define the color-coding function for the 'Combined Score' column
|
93 |
+
def color_combined_score(value):
|
94 |
+
"""Colors the combined score cell based on its value."""
|
95 |
+
if value > 0:
|
96 |
+
color = 'green'
|
97 |
+
elif value < 0:
|
98 |
+
color = 'red'
|
99 |
+
else:
|
100 |
+
color = 'none'
|
101 |
+
return f'background-color: {color};'
|
102 |
+
|
103 |
|
104 |
|
105 |
|