Can anyone please help understand why the following two ways of doing, what i thought was, otherwise the same thing with the pandas.dataframe groupby method, complete in such different times according to iPython's Magic %timeit?
%timeit somedf.groupby('someBoolColumn')['someBoolColumn'].count()
484 µs ± 9.52 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
%%timeit grp = somedf.groupby('someBoolColumn')
grp['someBoolColumn'].count()
146 µs ± 1.47 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
somedf has 7200 rows and 24 columns.
I cannot find,
why the two liner assigning the object to variable grp first is >3
times faster, nor;if this is just specific to the groupby method or something more general to pandas or even python, for example, about variable assigment.
Many thanks for any enlightenment as this would really help with many much larger dataframes i'd like to process, repeatedly with many different combinations of parameters.