<分区>
我不确定如何命名。
假设以下 Pandas DataFrame:
Student ID Class
1 John 99124 Biology
2 John 99124 History
3 John 99124 Geometry
4 Sarah 74323 Physics
5 Sarah 74323 Geography
6 Sarah 74323 Algebra
7 Alex 80045 Trigonometry
8 Alex 80045 Economics
9 Alex 80045 French
我想通过创建每个学生正在上的类(class)列表,然后将其放入“类(class)”列来减少此 DataFrame 中的行数。这是我想要的输出:
Student ID Class
1 John 99124 ["Biology","History","Geometry"]
2 Sarah 74323 ["Physics","Geography","Algebra"]
3 Alex 80045 ["Trigonometry","Economics","French"]
我正在使用一个大型 DataFrame,它不像这个例子那样组织得很好。感谢您的帮助。