• pandas的groupby.apply和直接apply效果是不一样的


    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直接传入参数

  • 相关阅读:
    SAP 是不是很烂的一个ERP软件
    Linux 的目录树
    LINUX连接外网的安全问题(查看日志)
    硬盘概念:柱面、磁道、扇区、簇
    Linux下安装PHP pdo_mysql支持
    端口映射帮助文档
    怎么建设一个FTP服务器
    linux开启telnet服务
    CentOS yum的详细使用方法
    WinXP SSH连接不上虚拟机的解决方法
  • 原文地址:https://www.cnblogs.com/dmesg/p/15931812.html
Copyright © 2020-2023  润新知