Site icon Amelt.net

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

Amelt

Amelt

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.