GroupBy.apply(func*args**kwargs)[source]

Apply function func group-wise and combine the results together.

The function passed to apply must take a dataframe as its first argument and return a DataFrame, Series or scalar. apply will then take care of combining the results back together into a single dataframe or series. apply is therefore a highly flexible grouping method.

While apply is a very flexible method, its downside is that using it can be quite a bit slower than using more specific methods like agg or transform. Pandas offers a wide range of method that will be much faster than using apply for their specific purposes, so try to use them before reaching for apply.

groupby的apply输入是一个df,输出也是一个df

DataFrame.apply(funcaxis=0raw=Falseresult_type=Noneargs=()**kwargs)[source]

Apply a function along an axis of the DataFrame.

Objects passed to the function are Series objects whose index is either the DataFrame’s index (axis=0) or the DataFrame’s columns (axis=1). By default (result_type=None), the final return type is inferred from the return type of the applied function. Otherwise, it depends on the result_type argument.

dataframe 的apply输入是一个元素。如果axis=1的话,那么输入就是一行的数据。

注意参数也是不一样的。dataframe的apply的args的是args=(),。而groupby的apply直接传入参数

pandas的groupby.apply和直接apply效果是不一样的的更多相关文章

  1. pandas 拆分groupby 应用某个函数apply 和聚合结果aggregate

    https://www.jianshu.com/p/2d49cb87626b df.groupby('A').size()

  2. pandas获取groupby分组里最大值所在的行,获取第一个等操作

    pandas获取groupby分组里最大值所在的行 10/May 2016 python pandas pandas获取groupby分组里最大值所在的行 如下面这个DataFrame,按照Mt分组, ...

  3. pandas之groupby分组与pivot_table透视表

    zhuanzi: https://blog.csdn.net/qq_33689414/article/details/78973267 pandas之groupby分组与pivot_table透视表 ...

  4. pandas之groupby分组与pivot_table透视

    一.groupby 类似excel的数据透视表,一般是按照行进行分组,使用方法如下. df.groupby(by=None, axis=0, level=None, as_index=True, so ...

  5. SQL Server outer apply 和 cross apply

    先说点题外话,因为后面我会用到这个函数. 前两天自定义了一个 sql 的字符串分割函数(Split),不过后来发现有点问题,例如: select * from Split(default,'123,4 ...

  6. SQL Server中CROSS APPLY和OUTER APPLY的应用详解

    SQL Server数据库操作中,在2005以上的版本新增加了一个APPLY表运算符的功能.新增的APPLY表运算符把右表表达式应用到左表表达式中的每一行.它不像JOIN那样先计算那个表表达式都可以, ...

  7. SQL 关于apply的两种形式cross apply 和 outer apply(转)

    转载链接:http://www.cnblogs.com/shuangnet/archive/2013/04/02/2995798.html apply有两种形式: cross apply 和 oute ...

  8. SQLServer count函数、cross apply和outer apply、

    1.COUNT(column_name) 函数返回指定列的值的数目(NULL 不计入)2.COUNT(*) 函数返回表中的记录数 select *   from TABLE_1 T1 outer ap ...

  9. SQL 关于apply的两种形式cross apply 和 outer apply

    SQL 关于apply的两种形式cross apply 和 outer apply 例子: CREATE TABLE [dbo].[Customers]( ) COLLATE Chinese_PRC_ ...

  10. SQL关于apply的两种形式cross apply和outer apply(转载)

    SQL 关于apply的两种形式cross apply 和 outer apply   apply有两种形式: cross apply 和 outer apply   先看看语法:   <lef ...

随机推荐

  1. javascript获取浏览器窗口分辨率|浏览器全屏分辨率|屏幕分辨率

    浏览器窗口分辨率指显示网页的区域,在PC端由于浏览器窗口大小可调节,这个值是可变的.在手机等移动端浏览器窗口大小不可调节,宽度值是固定的,但竖屏和横屏切换会改变. 浏览器全屏分辨率是指浏览器启用全屏显 ...

  2. 嵌入式Linux应用开发

    3-4 Makefile常用的函数 i.  $(foreach var,list,text) 简单地说,就是 for each var in list, change it to text. 对lis ...

  3. 攻防世界-fileclude

    攻防世界的一道文件包含题目 include("文件名"):会将文件中的内容视为代码块接入include所在代码中,输出的只是执行后的结果,文件中的注释.定义等无法查看. 本题中可以 ...

  4. oracle学习之redo

    Oracle的重做日志基本概念及原理 重做日志文件 redo log file 通常也称为日志文件,它是保证数据库安全和数据库备份与恢复的文件,是数据库安全和恢复的最基本的保障.管理员可以根据日志文集 ...

  5. zookeeper 选举流程源码解析

    在开始之前,我们先了解一下zookeeper集群角色,zookeeper中存在leader,follower, observer这么几个角色, leader, follower, 就类似与mysql ...

  6. Jupyter Notebook安装代码提示功能

    默认Jupyter Notebook没有安装代码提示功能,但是我们可以可通过如下命令安装和配置使得Jupyter Notebook具备代码提供功能. (确保Anaconda在环境变量里)1.电脑上搜索 ...

  7. outlook初用

    以前一直用 Foxmail 收发邮件,由于公司用到 sharepoint 可以跟 outlook 绑定,试了下 outlook. 第一次用 outlook 以为也是跟 foxmail 一样简单配置一下 ...

  8. vue项目运行出现warnings potentially fixable with the `--fix` option的报错问题

    vue-cil3 运行报错 warnings potentially fixable with the `--fix` option. 解决办法:"lint": "vue ...

  9. JiaoZiVideoPlayer模拟用户点击,切换播放引擎!~

    默认播放及模拟用户点击播放按钮 jzvideoPlayerStandard.startButton.performClick() 切换播放引擎及使用Ijkplayer JZVideoPlayer.se ...

  10. Nginx+Tomcat 负载均衡配置

    一.问题引入: Nginx+Tomcat 是目前主流的java web架构,如何让 nginx+tomcat 同时工作呢,也可以说如何使用 nginx 来反向代理 tomcat 后端均衡呢? 二.JA ...