Reputation: 316
I am working with pandas and I was wondering if there is a difference based on which statistical functions are applied as shown in the below examples and if there are certain situations where one is preferred over another.
df.groupby('A')['B'].agg('min')
df.groupby('A')['B'].min()
Upvotes: 0
Views: 393
Reputation: 1222
In my experience, there is no difference between them, cause, the underlying function is np.min
def min(self, numeric_only: bool = False, min_count: int = -1):
return self._agg_general(
numeric_only=numeric_only, min_count=min_count, alias="min", npfunc=np.min
)
npfunc=np.min
Upvotes: 0
Reputation: 10960
Both the code give the same desired output. But the agg
function is more versatile in terms of the number of functions to apply.
For example, you can do the following with agg
df.groupby('A')['B'].agg(['min', 'max', 'mean'])
Another difference is that, applying a single function i.e. min
will give you a Series
in your case and the output of agg
can either be a Series
or a DataFrame
Upvotes: 1