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. react hooks组件父组件调用子组件方法

    函数组件父组件调用子组件方法需要使用 useImperativeHandle 和 forwardRef 两个方法 1.子组件 2.父组件 注意:一定要使用ref来接从子组件传过来的实例值,用其他的在函 ...

  2. CentOS 7 安装步骤以及初始化

    2. 虚拟机分配的资源 因为用的软件不一样,这里设置方法无法截图,但大至如下: 2CPU/1G内存/200G硬盘 去掉打印机等没用的硬件(macOS要去掉打印机和摄像头) 光盘开始选择空白光盘,不要在 ...

  3. kube-proxy

    1 kube-proxy报错 "--random-fully" 解决: # yum install gcc make libnftnl-devel libmnl-devel aut ...

  4. maven静态资源过滤

    <resources> <resource> <directory>src/main/java</directory> <includes> ...

  5. (转) IIS隐藏响应头信息

    先安装url-rewrite组件 http://www.iis.net/downloads/microsoft/url-rewrite 修改应用根目录下的Web.config配置文件 <conf ...

  6. MVP模式(转)

    什么是MVP模式?     这个MVP可不是腾讯游戏<王者荣耀>中的MVP.我们今天要讨论的MVP其实同MVC一样,是一种编程模式和思想,也许更准确地讲是一种架构. MVP和MVC的区别  ...

  7. c++初始化和赋值的区别

    静态对象的声明及初始化不是赋值 声明(并缺省初始化)后再赋值 #include <iostream> #include <string> void fun(std::strin ...

  8. centos7 python2.7.5安装mysqldb

    1.安装pip,下载pip-20.3.1.tar.gz    解压python setup.py install 2.安装setuptools,下载setuptools-43.0.0.zip  解压p ...

  9. 睿爸信奥-【临阵磨枪】练习赛(第二场)- T2

    目录 题面 code 题面 徐老师在[睿爸信奥]里面颇受学生欢迎,有一天校长石老师想要搞个最受欢迎老师投票,徐老师就很想拿到这个奖.假设有 名候选者,有 人参加了投票,与以往不同的是,这次所有得票数超 ...

  10. C/C++ FILE 和 fstream 用法详解

    FILE 是C语言自带的文件操作结构体, fstream 是C++的文件操作类,两者使用都比较常见,且用法比较类似,再次记录. 功能 FILE fstream 打开文件 FILE* fopen(cha ...