How does it work? Pandas, groupby, get group

Let's say there is a table df, it has columns with the name "name", "class". Let there be lines named "x". If:

df_grouped = df.groupby("имя")
df_one_group = df_grouped.get_group("x")
df_one_group = df_one_group[["имя", "класс"]]

Accordingly, there is no error in the tc column "name", but if you wrap the cycle, everything works as it should:

df_grouped = df.groupby("имя")
for i in df["имя"].unique():  
    df_one_group = df_grouped.get_group(i)
    df_one_group = df_one_group[["имя", "класс"]]

Why is everything good in the loop, but without it, an error comes out?

Author: Deniz, 2020-05-05