🏆✅Beats 93% | Must watch |🐼Pandas
\n\n# Intuition\n Describe your first thoughts on how to solve this problem. \n\uD83E\uDD14 To determine which salespersons have not made any sales to a specifi
![Screenshot 2024-06-13 170021.png](https://assets.leetcode.com/users/images/b2ef459f-4a39-414a-9d86-6d3e14bbf804_1718278238.3548965.png)\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\uD83E\uDD14 To determine which salespersons have not made any sales to a specific company ("RED"), we can utilize joins and filtering operations. By isolating the sales related to the "RED" company and comparing them against the full list of salespersons, we can identify those who have no associated sales. \uD83D\uDD75\uFE0F\u200D\u2642\uFE0F\uD83D\uDCCA\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1) Identify "RED" Company ID \uD83D\uDCCB:\n\n* Extract the com_id of the company named "RED" from the Company table.\n2) Filter Orders for "RED" \uD83D\uDD0D:\n\n* Filter the Orders table to only include orders where com_id matches the "RED" company\'s ID.\n3) Mark Salespersons with Orders to "RED" \uD83C\uDFF7\uFE0F:\n\n* Create a flag for salespersons who have orders related to the "RED" company.\n4) Merge and Filter Salespersons \uD83D\uDD04:\n\n* Perform a left join between the SalesPerson table and the filtered Orders table.\n* Filter out salespersons who have a flag indicating an order related to "RED".\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(N)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(N)\n\n# Code\n```\nimport pandas as pd\n\ndef sales_person(sales_person: pd.DataFrame, company: pd.DataFrame, orders: pd.DataFrame) -> pd.DataFrame:\n    try:\n        red_id = company[(company.name == \'RED\')][\'com_id\'].iloc[0]\n        orders = orders[(orders[\'com_id\'] == red_id)]\n        orders = orders[[\'sales_id\']]\n        orders[\'flag\'] = 1\n        df = pd.merge(left=sales_person,right=orders,on=\'sales_id\',how=\'left\')\n        return df[(df.flag.isna())][[\'name\']]\n    except:\n        return sales_person[[\'name\']]\n```
['Pandas']