What is the difference between pandas agg and apply function?

前端 未结 4 1203
闹比i
闹比i 2020-11-29 03:55

I can\'t figure out the difference between Pandas .aggregate and .apply functions.
Take the following as an example: I load a dataset, do a

4条回答
  •  没有蜡笔的小新
    2020-11-29 04:41

    apply applies the function to each group (your Species). Your function returns 1, so you end up with 1 value for each of 3 groups.

    agg aggregates each column (feature) for each group, so you end up with one value per column per group.

    Do read the groupby docs, they're quite helpful. There are also a bunch of tutorials floating around the web.

提交回复
热议问题