Pandas solution with groupby(): beats 98% by runtime
Intuition\nUse groupby() method.\n\n# Approach\nStep 1. Count number of classes\nWe can group by "class" column and get the number of students assigned to each 
# Intuition\nUse groupby() method.\n\n# Approach\n**Step 1**. Count number of classes\nWe can group by "class" column and get the number of students assigned to each class:\n\n```\ngrouped = courses.groupby(\'class\')[\'student\'].count().reset_index()\n```\n\n\n**Step 2**. Select only required class / classes\n\nNext we need to select only the rows where number of \'student\' is more than 5:\n\n```\ngrouped = grouped[grouped[\'student\'] >= 5]\n```\n\n**Step 3**.\nIn return statement we only need to select one column and wrap it in double square brackets to make it DataFrame class.\n\n\n\n# Code\n```\nimport pandas as pd\n\ndef find_classes(courses: pd.DataFrame) -> pd.DataFrame:\n    grouped = courses.groupby(\'class\')[\'student\'].count().reset_index()\n    grouped = grouped[grouped[\'student\'] >= 5]\n    return grouped[[\'class\']]\n```
['Pandas']