Python,VAR:ValueError x contains a constant. Adding a constant with trend=’c’ is not allowed.

Published on:
Last updated:

This post is also available in: 日本語 (Japanese)

When I was doing data analysis in Python and dealing with the VAR model of statsmodels, I got the following error, so I wrote an article as a memo.

ValueError x contains a constant. Adding a constant with trend='c' is not allowed.

From what I've searched, the cause is that the data analyzed by the VAR model contains constant columns(columns that all have the same value).
It was caused by the process of filling the values ​​using fillna().

In this case, that columns were clearly unnecessary, so I deleted that columns.

df = df.drop('constant_columns', axis=1)
No tags for this post.

About
Kuniyoshi Takemoto is the founder of Amelt.net LLC, and editor of this blog(www.amelt.net).Learn more and follow me on LinkedIn.