Scipy优化与Pandas错误崩溃

时间:2017-11-06 13:44:52

标签: python numpy optimization scipy

我正在运行pandas 0.20和scipy 0.17.1。当我运行优化时:

res = minimize(run_opt, x0, method='COBYLA', constraints=cons, tol=None, callback=None, options={'disp': True, 'catol': 0.0002, 'maxiter': 1000, 'rhobeg': 1.0})

cons = ({'type':'ineq', 'fun':lambda t: t})

我在以下函数中运行的pandas查询中收到以下错误:

  File "H:script_1.py", line 159, in Fun_3
    Res_Table[i] = btst.query('Var_1=='+str(i+1))

  File "C:\Program Files\Anaconda2\lib\site-packages\pandas\core\frame.py", line 2116, in query
    res = self.eval(expr, **kwargs)

  File "C:\Program Files\Anaconda2\lib\site-packages\pandas\core\frame.py", line 2186, in eval
    return _eval(expr, inplace=inplace, **kwargs)

  File "C:\Program Files\Anaconda2\lib\site-packages\pandas\core\computation\eval.py", line 262, in eval
    truediv=truediv)

  File "C:\Program Files\Anaconda2\lib\site-packages\pandas\core\computation\expr.py", line 727, in __init__
    self.terms = self.parse()

  File "C:\Program Files\Anaconda2\lib\site-packages\pandas\core\computation\expr.py", line 744, in parse
    return self._visitor.visit(self.expr)

  File "C:\Program Files\Anaconda2\lib\site-packages\pandas\core\computation\expr.py", line 313, in visit
    return visitor(node, **kwargs)

  File "C:\Program Files\Anaconda2\lib\site-packages\pandas\core\computation\expr.py", line 319, in visit_Module
    return self.visit(expr, **kwargs)

  File "C:\Program Files\Anaconda2\lib\site-packages\pandas\core\computation\expr.py", line 313, in visit
    return visitor(node, **kwargs)

  File "C:\Program Files\Anaconda2\lib\site-packages\pandas\core\computation\expr.py", line 322, in visit_Expr
    return self.visit(node.value, **kwargs)

  File "C:\Program Files\Anaconda2\lib\site-packages\pandas\core\computation\expr.py", line 313, in visit
    return visitor(node, **kwargs)

  File "C:\Program Files\Anaconda2\lib\site-packages\pandas\core\computation\expr.py", line 644, in visit_Compare
    return self.visit(binop)

  File "C:\Program Files\Anaconda2\lib\site-packages\pandas\core\computation\expr.py", line 313, in visit
    return visitor(node, **kwargs)

  File "C:\Program Files\Anaconda2\lib\site-packages\pandas\core\computation\expr.py", line 416, in visit_BinOp
    op, op_class, left, right = self._maybe_transform_eq_ne(node)

  File "C:\Program Files\Anaconda2\lib\site-packages\pandas\core\computation\expr.py", line 354, in _maybe_transform_eq_ne
    left = self.visit(node.left, side='left')

  File "C:\Program Files\Anaconda2\lib\site-packages\pandas\core\computation\expr.py", line 313, in visit
    return visitor(node, **kwargs)

  File "C:\Program Files\Anaconda2\lib\site-packages\pandas\core\computation\expr.py", line 430, in visit_Name
    return self.term_type(node.id, self.env, **kwargs)

  File "C:\Program Files\Anaconda2\lib\site-packages\pandas\core\computation\ops.py", line 58, in __init__
    self._value = self._resolve_name()

  File "C:\Program Files\Anaconda2\lib\site-packages\pandas\core\computation\ops.py", line 75, in _resolve_name
    res = self.env.resolve(self.local_name, is_local=self.is_local)

  File "C:\Program Files\Anaconda2\lib\site-packages\pandas\core\computation\scope.py", line 192, in resolve
    raise compu.ops.UndefinedVariableError(key, is_local

其中Var_1是一个用于过滤Pandas DataFrame的列标题。错误经常发生,但不是在可预测的时刻发生。需要注意的是,如果函数“run_opt”在scipy优化环境之外执行,则执行得很好。

这可能是一个错误,还是我对如何使用scipy毫无头绪?任何输入都将受到大力赞赏!

0 个答案:

没有答案