Pandas DF与三列合并失败

时间:2018-06-15 00:06:00

标签: python pandas dataframe

我有以下df qty

qty = pd.DataFrame({"qty": [700,500,1000], 
                       "name": ['CB04 box',np.nan,'AB01 box'], 
                       "ccy": ['USD','AUS','USD'],
                      "product_type": ['A1','A1','B1'],
                   "iso": ['US','US','US']})

和另一个df item_info

item_info = pd.DataFrame({"product_type": ['A1','A2','A1'],
                       "currency": ['USD','USD','AUS'],
                       "name": ['CB04 box','CB01 Box','AB01 box'],
                         "country_code":['US','US','US']})

当我尝试使用此

合并以下两个DF时
values = qty.merge(item_info, left_on=["ccy","product_type","iso"],
                     right_on=["currency","product_type","country_code"],
             how="left", suffixes=("_qty", "_info"))["item_info"]

收到此错误

# duplicate columns & possible reduce dimensionality
KeyError: 'item_info'

0 个答案:

没有答案