0

I've written a test script to understand pandas.DataFrame().groupby().apply().

df=pd.DataFrame([("a",1),("b",2),("b",1)], columns=["idx", "col1"])

def my_apply(group):
    print(group)
    return group

df.groupby("idx").apply(my_apply)

As a result the dataframe for the group "a" is printed twice. It seems always the first one is called twice, but the result from the first call is thrown away.

Why does my_apply seem to be called twice for the first group?

Gere
  • 12,075
  • 18
  • 62
  • 94

0 Answers0