I'm trying to fit a linear model to some data using the code below. I'm getting the error below. I think the error has an issue with the '%' in the field name. I have many fields in my data with this naming convention. Does anyone know how to solve this issue with statsmodel?
code:
mod = ols('fieldA%'+'~'+'fieldB',data=smp_df).fit()
error:
Traceback (most recent call last):
File "C:\Users\username\AppDataPython\envs\py36\lib\site-packages\IPython\core\interactiveshell.py", line 3267, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-24-9e4f478cefb9>", line 3, in <module>
mod = ols('fieldA%'+' ~'+'fieldB',data=smp_df).fit()
File "C:\Users\username\AppDataPython\envs\py36\lib\site-packages\statsmodels\base\model.py", line 155, in from_formula
missing=missing)
File "C:\Users\username\AppDataPython\envs\py36\lib\site-packages\statsmodels\formula\formulatools.py", line 65, in handle_formula_data
NA_action=na_action)
File "C:\Users\username\AppDataPython\envs\py36\lib\site-packages\patsy\highlevel.py", line 310, in dmatrices
NA_action, return_type)
File "C:\Users\username\AppDataPython\envs\py36\lib\site-packages\patsy\highlevel.py", line 165, in _do_highlevel_design
NA_action)
File "C:\Users\username\AppDataPython\envs\py36\lib\site-packages\patsy\highlevel.py", line 70, in _try_incr_builders
NA_action)
File "C:\Users\username\AppDataPython\envs\py36\lib\site-packages\patsy\build.py", line 689, in design_matrix_builders
factor_states = _factors_memorize(all_factors, data_iter_maker, eval_env)
File "C:\Users\username\AppDataPython\envs\py36\lib\site-packages\patsy\build.py", line 354, in _factors_memorize
which_pass = factor.memorize_passes_needed(state, eval_env)
File "C:\Users\username\AppDataPython\envs\py36\lib\site-packages\patsy\eval.py", line 474, in memorize_passes_needed
subset_names = [name for name in ast_names(self.code)
File "C:\Users\username\AppDataPython\envs\py36\lib\site-packages\patsy\eval.py", line 474, in <listcomp>
subset_names = [name for name in ast_names(self.code)
File "C:\Users\username\AppDataPython\envs\py36\lib\site-packages\patsy\eval.py", line 105, in ast_names
for node in ast.walk(ast.parse(code)):
File "C:\Users\username\AppDataPython\envs\py36\lib\ast.py", line 35, in parse
return compile(source, filename, mode, PyCF_ONLY_AST)
File "<unknown>", line 1
CIM_ID_SALES %
^
SyntaxError: invalid syntax