# Why we add a constant value column in our DataFrame sometimes?

Currently I'm learning data science and I'm in the beginners stage. I have seen many times we add a "constant" column in our data frame with all row cells of that column having value 1.

I need to know why we do so. And also what will happen if we don't use it.

Thank you.

• Maybe as the reference column for one hot encoding of a categorical feature? This column is typically dropped though. Personally, I have never heard of anyone intentionally including a zero variance predictor into their model. That cannot provide any useful information in predicting your response (zero information with a constant variable) and can lead to numerical problems for some linear models. – aranglol Jul 13 '19 at 5:20
• Yes. Even I think adding this is of no use. But I think there could be some error if we don't use it. Is it so? – user9544852 Jul 13 '19 at 5:27
• I mean, what error could there be? In a one hot encoding example the constant column is dropped because we can infer the status of the last category through the other columns (you probably know this already). Are there any specific examples you can give in which this column is added? – aranglol Jul 13 '19 at 5:35
• Suppose, there is a DataFrame with columns GRE, GPA, Rank, Admission_Possibility ..here GRE is insignificant according to data and so we drop the GRE column and add a constant column to the DataFrame. – user9544852 Jul 13 '19 at 5:55
• That seems very suspect to me. What do you mean by insignificant? As in a statistical test in linear regression? Besides using p values for feature selection which is ill advised, most packages just drop any constant columns from the data frame because they introduce numerical problems (singular matrices). I am not too sure what the purpose of adding a constant column would do in your example or even why you would do that in the first place. Perhaps to keep the data frame in the same shape for convenience? Setting a column to all 1's that previously had a non constant variable... – aranglol Jul 13 '19 at 19:10

In linear regression you need that column to have lines which are not constrained to pass through origin. Think of linear model $$y = b_1 x_1 + b_2 x_2 + ...$$. Iff all $$x_i$$ are 0, y must be 0, you need an additional parameter to pass that constraint.
• +1: This is required in some packages (statsmodels in particular), and is the only time I've seen this done. – Ben Reiniger Jul 13 '19 at 21:34