I am talking about Python Pandas .agg()
function, this one:
meanData = all_data.groupby(['Id'])[features].agg('mean')
So, it can do things like:
What else can it do? I found nothing on the official documentation page: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.DataFrameGroupBy.agg.html
It can be just about any function that can be applied on a DataFrame
object.
print(dir(DataFrame))
When func
is a string type, the func name is looked up in the available attributes of the DataFrame
object that the .agg
method is invoked on.
https://github.com/pandas-dev/pandas/blob/v0.23.4/pandas/core/apply.py#L117
While it gives similar result when doing a division of elements in a DataFrame to write,
df = DataFrame([1,2,3,4])
df.agg('true_div', 0, 2)
In the real world, you find that the method doing the operation is invoked in a direct manner on the DataFrame
df = DataFrame([1,2,3,4])
df.true_div(2)
You can find the full list in documentation under pandas.core.groupby.GroupBy.some-function-name in the left menu.
List currently includes many aggregation functions:
pipe, all, any, bfill, backfill, count, cumcount, cummax, cummin, cumprod, cumsum, ffill, first, head, last, max, mean, median, min, ngroup, nth, ohlc, pad, prod, rank, pct_change, size, sem, std, sum, var, tail
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With