The apply method over a group seems to visit the first group twice · Issue #2656 · pandas-dev/pandas (original) (raw)
It seems that the apply method of a group invokes the function passed as parameter once for each group, as expectes. However, the function is invoked twice for the first group. Enclose is a short code reproducing this behavior. Is it a normal behavior or am I doing something wrong here.
I run the code with pandas 0.10.0 on. Windows 7, 32 bit version.
The code reproducing this behavior:
import pandas as pd
tdf = pd.DataFrame( { 'cat' : [1,1,1,2,2,1,1,2], 'B' : range(8)})
category = tdf['cat']
pGroups = tdf.groupby(by=category)
def getLen(df) :
print 'len ',len(df)
return len(df)
plen = pGroups.apply(getLen)