product_id
.store1
, store2
, store3
), use a CASE WHEN
statement to check if the store
column matches the store name, then select the price
.MAX
function to ensure that if there are multiple entries for a product-store combination, only one value is returned.product_id
to get one row per product..pivot()
method on the products
DataFrame.index='product_id'
, columns='store'
, and values='price'
to reshape the DataFrame.product_id
as the index and store names as column headers, with corresponding prices as values.erDiagram Products { int product_id enum store int price product_id store PK }