Pandas One Liner Solution beats 97% | Detailed Solution with each part breakthrough 🔮
\n\n# Approach\nWe can first fetch the company id which is alloted for company RED.\nThen we can get those sales person ids who have dealt with the company RED.
![image.png](https://assets.leetcode.com/users/images/5fd9c157-793f-4167-b589-4ad5c5c9d8b6_1692224467.6537435.png)\n\n# Approach\nWe can first fetch the company id which is alloted for company RED.\nThen we can get those sales person ids who have dealt with the company RED.\nAfter we have the sales persons who have dealt with company RED we can easily tell that the rest of the sales person haven\'t dealt with the company RED even a single time and can return there names.\n\n# Explaination\n\nHere is the detailed explaination for the solution mentioned below:\n1. First we will be fetching the com_id of company RED. For which we will simply use a boolean condition and use .com_id to fetch only the id which we require. This number will still be in Series datatype so we will convert it into integer.\n```\ncom=int(company[company[\'name\']==\'RED\'].com_id)\n```\n2. Now we need to get those sales person ids who have dealt with company RED. \nTo do this we can again use the boolean condition to match if any order have dealt with company RED and those who did what was the sales person id.\n```\nsales=orders[orders[\'com_id\']==com].sales_id\n```\n3. Now the last thing left is to return the sales person names who never dealt with the company RED. \nFor this, we will use isin function to fetch only those sales persons who have dealt with the company RED\n```\nsales_person[\'sales_id\'].isin(sales)\n```\n4. But we wanted sales person who haven\'t dealt so we will use logical NOT operator ~. and fetch only the names as required for the solution from the orders dataframe\n```\nreturn sales_person[~sales_person[\'sales_id\'].isin(sales)][[\'name\']]\n\n```\n\nNow, if we combine all these parts we can get a one liner solution for this problem.\n```\nreturn sales_person[~sales_person[\'sales_id\'].isin(orders[orders[\'com_id\']==int(company[company[\'name\']==\'RED\'].com_id)].sales_id)][[\'name\']] if \'RED\' in company[\'name\'].values else sales_person[[\'name\']]\n\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    # com=int(company[company[\'name\']==\'RED\'].com_id)\n    # sales=orders[orders[\'com_id\']==com].sales_id\n    # return sales_person[~sales_person[\'sales_id\'].isin(sales)][[\'name\']]\n    return sales_person[~sales_person[\'sales_id\'].isin(orders[orders[\'com_id\']==int(company[company[\'name\']==\'RED\'].com_id)].sales_id)][[\'name\']] if \'RED\' in company[\'name\'].values else sales_person[[\'name\']]\n```\n\n# Feedback\nIf this solution helped you even a bit, please consider UPVOTING, so this solution can reach to more people. \n![image.png](https://assets.leetcode.com/users/images/e05b4734-c84b-47d2-a1a6-2ef57f375c0c_1692224804.7293668.png)\n\n
['Pandas']