Patsy formula when variable has a hypthen

别来无恙 提交于 2020-07-23 07:22:05

问题


I am trying to use the statsmodel linear regression functions with formulas. My sample data is coming from a Pandas data frame. I am having a slight problem with column names within the formula. Due to the downstream processes, I have hyphens within my column names. For example:

+------+-------+-------+
+ VOLT +  B-NN + B-IDW +
+------+-------+-------+

Now, one of the reasons for keeping the hyphen as it allows python to split the string for other analysis, so I have to keep it. As you can see, when I want to regress VOLT with B-NN using VOLT ~ B-NN, I encounter a problem as the patsy formula cannot find B.

Is there a way to tell Patsy that B-NN is a variable name and not B minus NN?

Thanks.

BJR


回答1:


patsy uses Q for quoting names, e.g. Q('B-IDW')

http://patsy.readthedocs.io/en/latest/builtins-reference.html#patsy.builtins.Q

my_fit_function("y ~ Q('weight.in.kg')", ...)


来源:https://stackoverflow.com/questions/50623216/patsy-formula-when-variable-has-a-hypthen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!