代码之家  ›  专栏  ›  技术社区  ›  SBad

Left join and ValueError:传递的项数错误55,placement意味着1

  •  0
  • SBad  · 技术社区  · 6 年前

    我有两个数据帧

    • 一个大的:myTradeFrame(7401x27)
    • 一个小的:specialsData(3x3)

       coll_cusip tran_type  maturity_max
    0  912810SC3        BB          1.80
    1  912810SD1        BB          1.76
    2  9128284V9        BB          1.08
    

    代码是这样的:

    myTradeFrame['NewColumn']=pd.merge(myTradeFrame, specialsData, how='left', left_on = ['coll_cusip','tran_type'], right_on=[ 'coll_cusip', 'tran_type'])
    

    这行代码给出了一个错误,即使两个数据帧中都存在键列。我错过了什么?

    the error message i get is : 
        len(self.mgr_locs)))
    ValueError: Wrong number of items passed 55, placement implies 1
    During handling of the above exception, another exception occurred:
    Traceback (most recent call last):
      File "/apps/qtrinst/install/python/anaconda/envs/sx_anaconda/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2850, in run_ast_nodes
        if self.run_code(code, result):
      File "/apps/qtrinst/install/python/anaconda/envs/sx_anaconda/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2927, in run_code
        self.showtraceback(running_compiled_code=True)
    TypeError: showtraceback() got an unexpected keyword argument 'running_compiled_code'
    

    1 回复  |  直到 6 年前
        1
  •  1
  •   Abhishek Sharma    6 年前

    因此出现了错误。您可以用以下代码替换代码

    myTradeFrame = pd.merge(myTradeFrame, specialsData, how='left', on=[ 'coll_cusip', 'tran_type'],suffixes=('_left','_right'))
    

    提示:如果左数据帧和右数据帧中的键相同,只需使用on。