Python SyntaxError, выполняющая одностороннее выполнение Anova с использованием статистических моделей - PullRequest
0 голосов
/ 29 мая 2020

Попытка выяснить, есть ли существенные различия в общих продажах по сравнению с 10 различными штатами («Состояние» в рамке):

import statsmodels.api as sm
from statsmodels.formula.api import ols
mod = ols('Tot Sales ~ State', data=frame).fit()

Однако я получаю:

Traceback (most recent call last):

  File "/opt/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3326, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  File "<ipython-input-112-0ede3341fb4f>", line 1, in <module>
    mod = ols('Tot Sales ~ State', data=frame).fit()

  File "/opt/anaconda3/lib/python3.7/site-packages/statsmodels/base/model.py", line 159, in from_formula
    missing=missing)

  File "/opt/anaconda3/lib/python3.7/site-packages/statsmodels/formula/formulatools.py", line 65, in handle_formula_data
    NA_action=na_action)

  File "/opt/anaconda3/lib/python3.7/site-packages/patsy/highlevel.py", line 310, in dmatrices
    NA_action, return_type)

  File "/opt/anaconda3/lib/python3.7/site-packages/patsy/highlevel.py", line 165, in _do_highlevel_design
    NA_action)

  File "/opt/anaconda3/lib/python3.7/site-packages/patsy/highlevel.py", line 70, in _try_incr_builders
    NA_action)

  File "/opt/anaconda3/lib/python3.7/site-packages/patsy/build.py", line 689, in design_matrix_builders
    factor_states = _factors_memorize(all_factors, data_iter_maker, eval_env)

  File "/opt/anaconda3/lib/python3.7/site-packages/patsy/build.py", line 354, in _factors_memorize
    which_pass = factor.memorize_passes_needed(state, eval_env)

  File "/opt/anaconda3/lib/python3.7/site-packages/patsy/eval.py", line 474, in memorize_passes_needed
    subset_names = [name for name in ast_names(self.code)

  File "/opt/anaconda3/lib/python3.7/site-packages/patsy/eval.py", line 474, in <listcomp>
    subset_names = [name for name in ast_names(self.code)

  File "/opt/anaconda3/lib/python3.7/site-packages/patsy/eval.py", line 105, in ast_names
    for node in ast.walk(ast.parse(code)):

  File "/opt/anaconda3/lib/python3.7/ast.py", line 35, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)

  File "<unknown>", line 1
    Tot Sales
            ^
SyntaxError: invalid syntax

У меня такая же проблема со следующим, где он указывает на 't' в 'Amount':

mod = ols('Total Amount Charged ~ Country', data=frame).fit()

Извините, если это глупо, только начал с Python.

Заранее спасибо.

...