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. 可收集ALC问题[Microsoft.Data.SqlClient is not supported on this platform.]

    异常 Microsoft.Data.SqlClient is not supported on this platform. 堆栈跟踪 at Microsoft.Data.SqlClient.SqlC ...

  2. 【数据库数据恢复】Oracle数据库数据恢复案例

    数据库故障:Oracle数据库的ASM磁盘组掉线,ASM实例不能挂载.管理员尝试修复数据库但是没有成功. 数据库数据恢复方案:数据库数据恢复工程师通过分析组成ASM磁盘组的磁盘底层数据,将ASM元数据 ...

  3. golang 日志

    package log import ( "NOONASN/global" "github.com/natefinch/lumberjack" "go ...

  4. 脚本执行sudo命令时: 免手动确认和免输入密码

    1.sudo 命令有时候需要手动输入yes来确认执行 或者 软件在安装包下载完毕后还需要你输入y进行确认安装 .那如果是用脚本执行sudo 命令就可以用-y 参数来确认执行 sudo yum inst ...

  5. windows 设置网卡跳跃点

    查看路由表route print -4 添加永久路由表:192.168.1.1(网关)route add 0.0.0.0 mask 255.255.255.0 192.168.1.1 metric 1 ...

  6. MARKDEEP.js-一个轻松在HTML中输入MD代码的JavaScript库

    MARKDEEP.js-一个轻松在HTML中输入MD代码的JavaScript库 http://casual-effects.com/markdeep/ 引入: <style class=&qu ...

  7. Python - Numpy 学习笔记

    #python - Numpy learning import numpy as np #---Numpy学习笔记---(第四章)--- #切片,浅拷贝 a = np.arange(10) print ...

  8. 物理机安装mysql8, 修改数据库目录

    自动安装mysql ,并修改数据库目录. #! /bin/bash #mysql官方下载路径:https://dev.mysql.com/downloads/mysql/ # 配置dnf源 mkdir ...

  9. Idea报错:Command line is too long.

    https://blog.csdn.net/qq_40682764/article/details/109215368 run–>edit configurations–>你的项目–> ...

  10. EasyExcel工具使用

    pom文件: <dependency> <groupId>com.alibaba</groupId> <artifactId>easyexcel< ...