Role of key and df_key while using groupby function

what is the role of key and dfkey plz explain…

1 Like

I also need the answer for this. Please reply soon sir

Here key will represent all distinct values of df_thin[‘is_liked’] and df_key will represent the rows corresponding to those distinct keys in the table.
For e.g. let’s assume df_thin has only 5 rows.
And for 2 rows, the value of df_thin[‘is_liked’] is 0 and for remaining 3 rows, the value of df[‘is_liked’] is 1.
So here:
key = {0, 1} and
df_key will print the 2 rows where df_thin[‘is_liked’] is 0
df_key will print 3 rows where df_think[‘is_liked’] is 1.

so key and df_key are pre-defined keywords?

No, while iterating over g, key and df_key are just variable names used to hold the returned two values .
For example you could write the loop as:

for k, v in g:

Though key and df_key (data frame corresponding to key)seems more appropriate variable names.