我想知道如何按组有效地循环遍历行。因此,如下面的示例数据集所示,它包括 3 位不同的学生,他们在 3 个月内通过了记录。
import pandas as pd
import numpy as np
df = pd.DataFrame({'student':'A A A B B B C C C'.split(),
'month':[1, 2, 3, 1, 2, 3, 1, 2, 3],
'pass':[0, 1, 0, 0, 0, 0, 1, 0, 0]})
print(df)
student month pass
0 A 1 0
1 A 2 1
2 A 3 0
3 B 1 0
4 B 2 0
5 B 3 0
6 C 1 1
7 C 2 0
8 C …Run Code Online (Sandbox Code Playgroud)