minor internal changes ahead of company tab release
Browse files- src/app_utils.py +29 -2
src/app_utils.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import pandas as pd
|
| 2 |
-
from typing import
|
| 3 |
|
| 4 |
import re
|
| 5 |
|
|
@@ -66,4 +66,31 @@ def styler_negative_red(df: pd.DataFrame, cols: list[str] | None = None):
|
|
| 66 |
pass
|
| 67 |
return ""
|
| 68 |
|
| 69 |
-
return df.style.applymap(_style, subset=cols)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
+
from typing import Tuple
|
| 3 |
|
| 4 |
import re
|
| 5 |
|
|
|
|
| 66 |
pass
|
| 67 |
return ""
|
| 68 |
|
| 69 |
+
return df.style.applymap(_style, subset=cols)
|
| 70 |
+
|
| 71 |
+
def get_company_info(
|
| 72 |
+
maestro: pd.DataFrame,
|
| 73 |
+
ticker: str,
|
| 74 |
+
rename_columns: dict
|
| 75 |
+
) -> Tuple[str, str, pd.DataFrame]:
|
| 76 |
+
"""
|
| 77 |
+
Returns the company name, longBusinessSummary, and a DataFrame
|
| 78 |
+
of all other fields for the given ticker.
|
| 79 |
+
"""
|
| 80 |
+
company = maestro[maestro["ticker"] == ticker]
|
| 81 |
+
if company.empty:
|
| 82 |
+
return ticker, "No data available.", pd.DataFrame()
|
| 83 |
+
|
| 84 |
+
# extract name & summary
|
| 85 |
+
name = company["security"].iloc[0] if "security" in company.columns else ticker
|
| 86 |
+
summary = company["longBusinessSummary"].iloc[0] if "longBusinessSummary" in company.columns else ""
|
| 87 |
+
|
| 88 |
+
# build details table
|
| 89 |
+
details = company.drop(columns=["longBusinessSummary"], errors="ignore").iloc[0]
|
| 90 |
+
df = pd.DataFrame({
|
| 91 |
+
"Field": details.index.tolist(),
|
| 92 |
+
"Value": details.values.tolist()
|
| 93 |
+
})
|
| 94 |
+
df["Field"] = df["Field"].map(lambda c: rename_columns.get(c, c))
|
| 95 |
+
|
| 96 |
+
return name, summary, df
|