Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -37,7 +37,21 @@ def _airline_passengers() -> pd.DataFrame:
|
|
| 37 |
import statsmodels.api as sm
|
| 38 |
data = sm.datasets.get_rdataset("AirPassengers", "datasets").data
|
| 39 |
dates = pd.date_range(start="1949-01-01", periods=len(data), freq="MS")
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
except Exception:
|
| 42 |
# Fallback: generate the well-known series manually
|
| 43 |
np.random.seed(0)
|
|
|
|
| 37 |
import statsmodels.api as sm
|
| 38 |
data = sm.datasets.get_rdataset("AirPassengers", "datasets").data
|
| 39 |
dates = pd.date_range(start="1949-01-01", periods=len(data), freq="MS")
|
| 40 |
+
# Prefer common value column names from Rdatasets
|
| 41 |
+
candidate_cols = [c for c in ["value", "passengers", "x"] if c in data.columns]
|
| 42 |
+
|
| 43 |
+
if candidate_cols:
|
| 44 |
+
y = pd.to_numeric(data[candidate_cols[0]], errors="coerce").to_numpy()
|
| 45 |
+
else:
|
| 46 |
+
# Fallback: take the last numeric column (and avoid obvious time columns)
|
| 47 |
+
numeric_cols = data.select_dtypes(include=["number"]).columns.tolist()
|
| 48 |
+
drop_cols = [c for c in ["time", "date", "year", "month"] if c in numeric_cols]
|
| 49 |
+
numeric_cols = [c for c in numeric_cols if c not in drop_cols]
|
| 50 |
+
if not numeric_cols:
|
| 51 |
+
raise ValueError(f"Could not identify value column in AirPassengers data: {list(data.columns)}")
|
| 52 |
+
y = pd.to_numeric(data[numeric_cols[-1]], errors="coerce").to_numpy()
|
| 53 |
+
|
| 54 |
+
return pd.DataFrame({"ds": dates, "y": y})
|
| 55 |
except Exception:
|
| 56 |
# Fallback: generate the well-known series manually
|
| 57 |
np.random.seed(0)
|