Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -210,10 +210,25 @@ with st.expander("Train with Indicators (RSI, EMA, Stochastic)"):
|
|
| 210 |
)
|
| 211 |
if df.empty:
|
| 212 |
st.error("No data returned. Try a shorter lookback for intraday (e.g., 30d/60d) or use Interval=1d.")
|
| 213 |
-
st.stop()
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
|
| 218 |
# 2) Indicators (helpers above)
|
| 219 |
df["rsi14"] = rsi(df["Close"], 14)
|
|
|
|
| 210 |
)
|
| 211 |
if df.empty:
|
| 212 |
st.error("No data returned. Try a shorter lookback for intraday (e.g., 30d/60d) or use Interval=1d.")
|
| 213 |
+
st.stop() # Handle MultiIndex columns (yfinance can return 2-level columns)
|
| 214 |
+
if isinstance(df.columns, pd.MultiIndex):
|
| 215 |
+
try:
|
| 216 |
+
sym = df.columns.get_level_values(1).unique()[0]
|
| 217 |
+
df = df.xs(sym, axis=1, level=1)
|
| 218 |
+
except Exception:
|
| 219 |
+
# Fallback: flatten by taking the top-level name (Close/High/Low)
|
| 220 |
+
df.columns = [c[0] for c in df.columns.to_flat_index()]
|
| 221 |
+
|
| 222 |
+
# Keep only needed cols
|
| 223 |
+
df = df[["Close", "High", "Low"]].copy()
|
| 224 |
+
|
| 225 |
+
# Ensure each column is 1-D (avoid (N,1) arrays)
|
| 226 |
+
for _c in ["Close", "High", "Low"]:
|
| 227 |
+
if isinstance(df[_c], pd.DataFrame):
|
| 228 |
+
df[_c] = df[_c].iloc[:, 0]
|
| 229 |
+
df[_c] = pd.Series(np.asarray(df[_c]).reshape(-1), index=df.index)
|
| 230 |
+
|
| 231 |
+
df = df.dropna()
|
| 232 |
|
| 233 |
# 2) Indicators (helpers above)
|
| 234 |
df["rsi14"] = rsi(df["Close"], 14)
|