The problem is that C
is the name of one of the columns in your DataFrame as well as the patsy way of denoting that you want a categorical variable. The easiest fix would be to just rename the column as such:
data = data.rename_axis({'C': 'C_data'}, axis=1)
form = "C_data ~ Q1 + Q2 + Q3 + Q4 + Q5 + C(BANK)"
Then the call to sm.ols
will just work.
The error message TypeError: 'Series' object is not callable
can be interpreted as follows:
- patsy interprets
C
as the column of the data frame. In this case it would the Seriesdata['C']
- Then the fact that this is followed immediately by parenthesis made statsmodels try to call the
data['C']
as a function with the argumentBANK
. Series objects don't implement a__call__
method, hence the error message that the'Series' object is not callable
.
Good luck!