To transform a pandas DataFrame to a numpy array for use with the statsmodels.ols function, you can use the .values attribute of the DataFrame. Here's an example:
main.py423 chars23 lines
In this example, we create a pandas DataFrame with three columns: x1, x2, and y. We then convert the x1 and x2 columns to a numpy array X using the .values attribute, and the y column to a numpy array y. Finally, we fit an OLS model using sm.OLS and the converted numpy arrays X and y.
gistlibby LogSnag