FutureWarning: Method .ptp FutureWarning: Method .ptp numpy numpy

FutureWarning: Method .ptp


weekly[predictors] will return a Series representation of the weekly[[predictors]] DataFrame. Since the warning tells to use numpy.ptp, then by adding the attribute values to weekly[predictors] will make the warning disappeared, i.e.

X = sm.add_constant(weekly[predictors].values)

or you can use the method to_numpy():

X = sm.add_constant(weekly[predictors].to_numpy())

It will convert the weekly[predictors] Series to a NumPy array.


The line which generate this warning is this:

X = sm.add_constant(weekly[predictors]) # sm: statsmodels

Unfortunately i have the same issue.


The line that causes the warning is:

X = sm.add_constant(weekly[predictors]) # sm: statsmodels

This is a utility from statsmodels that adds a column called const to the data frame with all 1.

Since it doesn't work anymore (uses a deprecated function), you can use a different method. I prefer pandas' built-in assign method:

X = weekly[predictors].assign(const=1)

Or even, call it Intercept because that's what that constant is for, and to be consistent with the formula api in statsmodels.

X = weekly[predictors].assign(Intercept=1)