python - Odd results from simple group by -
the code below returning information not expecting. issue or missing something?
import pandas pd df = pd.dataframe({'symbol':['a','b','c'], 'volume':[561,56,8]}) group = df.groupby('symbol') def f1(group): print group return group group.apply(f1)
i getting:
symbol volume 0 561 symbol volume 0 561 symbol volume 1 b 56 symbol volume 2 c 8
as can see issue print statement. getting group "a" twice , not sure if bug. can confirm?
pandas version : '0.14.1'
from pandas documentation:
warning: in current implementation apply calls func twice on first group decide whether can take fast or slow code path. can lead unexpected behavior if func has side-effects, take effect twice first group.
that's why method called once on first group. it's by-implementation.
Comments
Post a Comment