top of page
import pandas as pd
data = [['A', 'Math'], ['B', 'English'], ['C', 'Math'], ['D', 'Biology'], ['E', 'Math'], ['F', 'Computer'], ['G', 'Math'], ['H', 'Math'], ['I', 'Math']]
courses = pd.DataFrame(data, columns=['student', 'class']).astype({'student':'object', 'class':'object'})
def find_classes(courses: pd.DataFrame) -> pd.DataFrame:
class_counts = courses["class"].value_counts().reset_index()
class_counts = class_counts[class_counts["count"]>=5]
class_counts = class_counts[['class']]
return class_counts
result = find_classes(courses)
print(result)
bottom of page