Here is a simple DataFrame:
import numpy as np
dd=pd.DataFrame(np.arange(35).reshape(7,5), columns=list('xyzwv'))
dd['w']=list('AABBBCC')
,which is:
Now I try the following code
def func(x):
print(x)
return x
dd.groupby('w').apply(func)
then it prints out:
I think something goes wrong because
is being printed twice.
It looks as if func() is being called twice for the same group. What mistake did I do?