{"action":"created","issue":{"url":"https://api.github.com/repos/pandas-dev/pandas/issues/14668","repository_url":"https://api.github.com/repos/pandas-dev/pandas","labels_url":"https://api.github.com/repos/pandas-dev/pandas/issues/14668/labels{/name}","comments_url":"https://api.github.com/repos/pandas-dev/pandas/issues/14668/comments","events_url":"https://api.github.com/repos/pandas-dev/pandas/issues/14668/events","html_url":"https://github.com/pandas-dev/pandas/pull/14668","id":189561770,"number":14668,"title":"ENH: add Series & DataFrame .agg/.aggregate","user":{"login":"jreback","id":953992,"avatar_url":"https://avatars.githubusercontent.com/u/953992?v=3","gravatar_id":"","url":"https://api.github.com/users/jreback","html_url":"https://github.com/jreback","followers_url":"https://api.github.com/users/jreback/followers","following_url":"https://api.github.com/users/jreback/following{/other_user}","gists_url":"https://api.github.com/users/jreback/gists{/gist_id}","starred_url":"https://api.github.com/users/jreback/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jreback/subscriptions","organizations_url":"https://api.github.com/users/jreback/orgs","repos_url":"https://api.github.com/users/jreback/repos","events_url":"https://api.github.com/users/jreback/events{/privacy}","received_events_url":"https://api.github.com/users/jreback/received_events","type":"User","site_admin":false},"labels":[{"id":35818298,"url":"https://api.github.com/repos/pandas-dev/pandas/labels/API%20Design","name":"API Design","color":"AD7FA8","default":false},{"id":76812,"url":"https://api.github.com/repos/pandas-dev/pandas/labels/Enhancement","name":"Enhancement","color":"4E9A06","default":false},{"id":13098779,"url":"https://api.github.com/repos/pandas-dev/pandas/labels/Reshaping","name":"Reshaping","color":"02d7e1","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/pandas-dev/pandas/milestones/39","html_url":"https://github.com/pandas-dev/pandas/milestone/39","labels_url":"https://api.github.com/repos/pandas-dev/pandas/milestones/39/labels","id":1570595,"number":39,"title":"0.20.0","description":"after 0.19.x series","creator":{"login":"jreback","id":953992,"avatar_url":"https://avatars.githubusercontent.com/u/953992?v=3","gravatar_id":"","url":"https://api.github.com/users/jreback","html_url":"https://github.com/jreback","followers_url":"https://api.github.com/users/jreback/followers","following_url":"https://api.github.com/users/jreback/following{/other_user}","gists_url":"https://api.github.com/users/jreback/gists{/gist_id}","starred_url":"https://api.github.com/users/jreback/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jreback/subscriptions","organizations_url":"https://api.github.com/users/jreback/orgs","repos_url":"https://api.github.com/users/jreback/repos","events_url":"https://api.github.com/users/jreback/events{/privacy}","received_events_url":"https://api.github.com/users/jreback/received_events","type":"User","site_admin":false},"open_issues":155,"closed_issues":181,"state":"open","created_at":"2016-02-08T15:30:21Z","updated_at":"2016-12-27T22:24:56Z","due_on":"2017-02-28T08:00:00Z","closed_at":null},"comments":12,"created_at":"2016-11-16T02:03:39Z","updated_at":"2016-12-28T12:16:55Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/pandas-dev/pandas/pulls/14668","html_url":"https://github.com/pandas-dev/pandas/pull/14668","diff_url":"https://github.com/pandas-dev/pandas/pull/14668.diff","patch_url":"https://github.com/pandas-dev/pandas/pull/14668.patch"},"body":"- to provide convienent function application that mimics the groupby(..).agg/.aggregate\r\ninterface\r\n- ``.apply`` is now a synonym for ``.agg/.aggregate``, and will accept dict/list-likes\r\nfor aggregations\r\n- Automatic handling of both reductive and transformation functions, e.g.``Series.agg(['min', 'sqrt'])``\r\n- interpretation of string names on series (with a fallback to numpy), e.g. ``sqrt``, ``log``)\r\n\r\ncloses #1623\r\ncloses #14464\r\n\r\ncustom .describe. I included these issues because its is quite easy to now do custom .describe.\r\ncloses #14483\r\ncloses #7014\r\n\r\nTODO:\r\n- [ ] docs (new section in basics, with linking to groupby, rolling, resample aggregates sections)\r\n- [ ] tests for``Series.agg({'foo' : ['min', 'max']})``\r\n- [ ] update doc-strings\r\n\r\nSeries:\r\n```\r\nIn [2]: s = Series(range(6))\r\n\r\nIn [3]: s\r\nOut[3]: \r\n0    0\r\n1    1\r\n2    2\r\n3    3\r\n4    4\r\n5    5\r\ndtype: int64\r\n\r\nIn [4]: s.agg(['min', 'max'])\r\nOut[4]: \r\nmin    0\r\nmax    5\r\ndtype: int64\r\n\r\nIn [5]: s.agg(['sqrt', 'min'])\r\nValueError: cannot combine transform and aggregation operations\r\n\r\nIn [6]: s.agg({'foo' : 'min'})\r\nOut[6]: \r\nfoo    0\r\ndtype: int64\r\n\r\nIn [7]: s.agg({'foo' : ['min','max']})\r\nOut[7]: \r\n     foo\r\nmin    0\r\nmax    5\r\n\r\nIn [8]: s.agg({'foo' : ['min','max'], 'bar' : ['sum', 'mean']})\r\nOut[8]: \r\n      foo   bar\r\nmax   5.0   NaN\r\nmean  NaN   2.5\r\nmin   0.0   NaN\r\nsum   NaN  15.0\r\n```\r\n\r\nDataFrame\r\n```\r\nIn [8]: df = pd.DataFrame({'A': range(5), 'B': 5})\r\n\r\nIn [9]: df\r\nOut[9]: \r\n   A  B\r\n0  0  5\r\n1  1  5\r\n2  2  5\r\n3  3  5\r\n4  4  5\r\n\r\nIn [10]: df.agg(['min', 'max'])\r\nOut[10]: \r\n     A  B\r\nmin  0  5\r\nmax  4  5\r\n\r\nIn [11]: df.agg({'A': ['min', 'max'], 'B': ['sum', 'max']})\r\nOut[11]: \r\n       A     B\r\nmax  4.0   5.0\r\nmin  0.0   NaN\r\nsum  NaN  25.0\r\n\r\n# df.agg is equivalent to a tranfsorm\r\nIn [15]: df.transform([np.sqrt, np.abs, lambda x: x**2])\r\nOut[15]: \r\n          A                           B                  \r\n       sqrt absolute <lambda>      sqrt absolute <lambda>\r\n0  0.000000        0        0  2.236068        5       25\r\n1  1.000000        1        1  2.236068        5       25\r\n2  1.414214        2        4  2.236068        5       25\r\n3  1.732051        3        9  2.236068        5       25\r\n4  2.000000        4       16  2.236068        5       25\r\n\r\n```\r\n\r\nNot sure what I should do in cases like this. could skip, or maybe raise better message.\r\n```\r\nIn [16]: df = pd.DataFrame({'A': range(5), 'B': 5, 'C':'foo'})\r\n\r\nIn [17]: df\r\nOut[17]: \r\n   A  B    C\r\n0  0  5  foo\r\n1  1  5  foo\r\n2  2  5  foo\r\n3  3  5  foo\r\n4  4  5  foo\r\n\r\nIn [18]: df.transform(['log', 'abs'])\r\nAttributeError: 'str' object has no attribute 'log'\r\n```"},"comment":{"url":"https://api.github.com/repos/pandas-dev/pandas/issues/comments/269469475","html_url":"https://github.com/pandas-dev/pandas/pull/14668#issuecomment-269469475","issue_url":"https://api.github.com/repos/pandas-dev/pandas/issues/14668","id":269469475,"user":{"login":"jorisvandenbossche","id":1020496,"avatar_url":"https://avatars.githubusercontent.com/u/1020496?v=3","gravatar_id":"","url":"https://api.github.com/users/jorisvandenbossche","html_url":"https://github.com/jorisvandenbossche","followers_url":"https://api.github.com/users/jorisvandenbossche/followers","following_url":"https://api.github.com/users/jorisvandenbossche/following{/other_user}","gists_url":"https://api.github.com/users/jorisvandenbossche/gists{/gist_id}","starred_url":"https://api.github.com/users/jorisvandenbossche/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jorisvandenbossche/subscriptions","organizations_url":"https://api.github.com/users/jorisvandenbossche/orgs","repos_url":"https://api.github.com/users/jorisvandenbossche/repos","events_url":"https://api.github.com/users/jorisvandenbossche/events{/privacy}","received_events_url":"https://api.github.com/users/jorisvandenbossche/received_events","type":"User","site_admin":false},"created_at":"2016-12-28T12:16:55Z","updated_at":"2016-12-28T12:16:55Z","body":"@jreback I also had a strange issue when testing:\r\n\r\n```\r\nIn [17]: df = pd.DataFrame({'A': range(6), 'B': 5}, index=range(6))\r\n\r\nIn [18]: df\r\nOut[18]: \r\n   A  B\r\n0  0  5\r\n1  1  5\r\n2  2  5\r\n3  3  5\r\n4  4  5\r\n5  5  5\r\n\r\nIn [19]: df.agg(lambda x: 1)\r\nOut[19]: \r\nA    1\r\nB    1\r\ndtype: int64\r\n\r\nIn [20]: df.agg([lambda x: 1])\r\nOut[20]: \r\n         A        B\r\n  <lambda> <lambda>\r\n0        1        1\r\n1        1        1\r\n2        1        1\r\n3        1        1\r\n4        1        1\r\n5        1        1\r\n```\r\n\r\nI often test with dummy functions like the above with a clear return shape of the single function (so here it is a custom passed reducing function that returns a scalar). In the first case it works, but when passing it in a list, it does not work.\r\n\r\nIf I slightly adapt the function:\r\n\r\n```\r\nIn [24]: df.agg([lambda x: min(1, x.max())])\r\nOut[24]: \r\n          A  B\r\n<lambda>  1  1\r\n```\r\nthen this now does work, although the function this returns exactly the same for all columns."}}
{"actor":{"display_login":"jorisvandenbossche"}}