Suppose I have two dataframes; one holds transactions, trans
and the other holds product information, prod
, and I want to join the product prices, the variable price
, on to the transaction data frame, repeating them down for each column. Which of these approaches is more efficient / preferred:
Method 1:
trans = trans.set_index('product_id').join(trans.set_index('product_id'))
Method 2:
trans.set_index('product_id',inplace=True)
trans['price'] = prod.loc[trans.product_id, 'price']