🔥💯✅[Pandas] Simple Easy to understand 🔥💯✅
\n# Approach\n Describe your approach to solving the problem. \n1.  Create an empty list to store the rearranged rows\n2. Iterate over each row in the original 
\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1.  Create an empty list to store the rearranged rows\n2. Iterate over each row in the original products DataFrame.\n3. For each row, extract the product_id value.\n\n4. Check each store column (store1, store2, and store3) for price availability.\n\n5. Get the price value from the current store column.\n\n6. Check if the price is not null (i.e., the product is available in that store).\n\n7. If the price is not null, add a new row to the list with the values (product_id, store, price).\n\n8. After processing all rows, create a new DataFrame using the list of rearranged rows.\n\n9. The new DataFrame will have three columns: product_id, store, and price.\n\n10. Return the newly created DataFrame containing the rearranged table structure.\n# Code\n```\nimport pandas as pd\n\ndef rearrange_products_table(products: pd.DataFrame) -> pd.DataFrame:\n    # Create an empty list to store the rearranged rows\n    rearranged_rows = []\n\n    # Iterate over each row in the original table\n    for _, row in products.iterrows():\n        product_id = row[\'product_id\']\n\n        # Check each store for price availability\n        for store_col in [\'store1\', \'store2\', \'store3\']:\n            price = row[store_col]\n            if pd.notna(price):\n                # If the price is not null, add the (product_id, store, price) tuple to the list\n                rearranged_rows.append((product_id, store_col, price))\n\n    # Create a new DataFrame with the rearranged rows\n    result_table = pd.DataFrame(rearranged_rows, columns=[\'product_id\', \'store\', \'price\'])\n\n    return result_table\n```\n![upvote img.jpg](https://assets.leetcode.com/users/images/7625000a-89a9-4418-bfff-05b1726a78ca_1691162555.623444.jpeg)\n
['Pandas']