

「python 実践データ分析100本ノック」のノック66番の生産最適化問題を解く中で  
typeerrorが出てしまい止まってしまっております。  
エラー文によると'errors'が予期せぬ引数として受け付けられていないようなのですが  
修正方法がどう調べてもわからず質問させていただきました。  
8行目の処理で↑の問題が発生しているようです。

[code]

    import pandas as pd
    from pulp import LpVariable, lpSum, value
    from ortoolpy import model_max, addvars, addvals
    
    df = df_material.copy()
    inv = df_stock
    
    m = model_max()
    v1 = {(i):LpVariable('v%d'%(i),lowBound=0) for i in range(len(df_profit))}
    m += lpSum(df_profit.iloc[i]*v1[i] for i in range(len(df_profit)))
    for i in range(len(df_material.columns)):
        m += lpSum(df_material.iloc[j,i]*v1[j] for j in range(len(df_profit)) ) <= df_stock.iloc[:,i]
    m.solve()
    
    df_plan_sol = df_plan.copy()
    for k,x in v1.items():
        df_plan_sol.iloc[k] = value(x)
    print(df_plan_sol)
    print("総利益:"+str(value(m.objective)))
    
[/code]

エラー文は下記となります。答えがついているので試しに実行したところ  
全く同じコードで自分で試したときのみこちらのエラーが出ております。

[code]

    TypeError                                 Traceback (most recent call last)
    <ipython-input-54-eb07d530edd3> in <module>
          9 m = model_max()
         10 v1 = {(i):LpVariable('v%d'%(i),lowBound=0) for i in range(len(df_profit))}
    ---> 11 m += lpSum(df_profit.iloc[i]*v1[i] for i in range(len(df_profit)))
         12 for i in range(len(df_material.columns)):
         13     m += lpSum(df_material.iloc[j,i]*v1[j] for j in range(len(df_profit)) ) <= df_stock.iloc[:,i]
    
    ~\anaconda3\lib\site-packages\pulp\pulp.py in lpSum(vector)
       2246     :param vector: A list of linear expressions
       2247     """
    -> 2248     return LpAffineExpression().addInPlace(vector)
       2249 
       2250 
    
    ~\anaconda3\lib\site-packages\pulp\pulp.py in addInPlace(self, other)
        858                 self.addInPlace(e)
        859         elif isinstance(other, list) or isinstance(other, Iterable):
    --> 860             for e in other:
        861                 self.addInPlace(e)
        862         else:
    
    <ipython-input-54-eb07d530edd3> in <genexpr>(.0)
          9 m = model_max()
         10 v1 = {(i):LpVariable('v%d'%(i),lowBound=0) for i in range(len(df_profit))}
    ---> 11 m += lpSum(df_profit.iloc[i]*v1[i] for i in range(len(df_profit)))
         12 for i in range(len(df_material.columns)):
         13     m += lpSum(df_material.iloc[j,i]*v1[j] for j in range(len(df_profit)) ) <= df_stock.iloc[:,i]
    
    ~\anaconda3\lib\site-packages\pandas\core\ops\common.py in new_method(self, other)
         63                     break
         64                 if isinstance(other, cls):
    ---> 65                     return NotImplemented
         66 
         67         other = item_from_zerodim(other)
    
    ~\anaconda3\lib\site-packages\pandas\core\ops\__init__.py in wrapper(left, right)
        341 
        342 
    --> 343 def frame_arith_method_with_reindex(left: DataFrame, right: DataFrame, op) -> DataFrame:
        344     """
        345     For DataFrame-with-DataFrame operations that require reindexing,
    
    ~\anaconda3\lib\site-packages\pandas\core\ops\array_ops.py in arithmetic_op(left, right, op)
        188 
        189     Note: the caller is responsible for ensuring that numpy warnings are
    --> 190     suppressed (with np.errstate(all="ignore")) if needed.
        191 
        192     Parameters
    
    ~\anaconda3\lib\site-packages\pandas\core\ops\array_ops.py in na_arithmetic_op(left, right, op, is_cmp)
        138 def _na_arithmetic_op(left, right, op, is_cmp: bool = False):
        139     """
    --> 140     Return the result of evaluating op on the passed in values.
        141 
        142     If native types are not compatible, try coercion to object dtype.
    
    ~\anaconda3\lib\site-packages\pandas\core\computation\expressions.py in <module>
         17 from pandas._typing import FuncType
         18 
    ---> 19 from pandas.core.computation.check import NUMEXPR_INSTALLED
         20 from pandas.core.ops import roperator
         21 
    
    ~\anaconda3\lib\site-packages\pandas\core\computation\check.py in <module>
          1 from pandas.compat._optional import import_optional_dependency
          2 
    ----> 3 ne = import_optional_dependency("numexpr", errors="warn")
          4 NUMEXPR_INSTALLED = ne is not None
          5 if NUMEXPR_INSTALLED:
    
    TypeError: import_optional_dependency() got an unexpected keyword argument 'errors'
    
[/code]


CC BY-SA 4.0
2021-08-12T09:21:33.720
80751
2021-08-12T09:32:48.267
2021-08-12T09:32:48.267
26370
47685
question
python jupyter-notebook
python errorsが引数のtypeerrorに関して