Preparing Data for VARData¶
This guide shows how to construct a VARData container from common data formats.
From a pandas DataFrame¶
The simplest path is VARData.from_df. Your DataFrame must have a DatetimeIndex:
import pandas as pd
from impulso import VARData
df = pd.read_csv("macro_data.csv", index_col="date", parse_dates=True)
data = VARData.from_df(df, endog=["gdp", "inflation", "rate"])
With exogenous variables¶
Pass column names for exogenous variables separately:
From NumPy arrays¶
If you already have arrays, pass them directly:
import numpy as np
data = VARData(
endog=endog_array, # shape (T, n), n >= 2
endog_names=["gdp", "inflation", "rate"],
index=pd.date_range("2000-01-01", periods=T, freq="QS"),
)
Validation rules¶
VARData enforces these constraints at construction time:
- At least 2 endogenous variables
- No
NaNorInfvalues endog_nameslength must match number of columnsindexlength must match number of rows- If
exogis provided,exog_namesis required (and vice versa) - Arrays are copied and made read-only — the original data is never modified