zoukankan      html  css  js  c++  java
  • python apply函数

    函数格式为:apply(func,*args,**kwargs)

    函数主要用于对DataFrame中的某一column或row中的元素执行相同的函数操作。

    对某一列(column)进行操作

    # 对C1列中的每一个元素加1
    df["C1"].apply(lambda x:x+1)

    对某一行(row)进行操作

    # 对第1行的每一个元素加1
    df.loc[1].apply(lambda x:x+1)

    apply()也可对DataFrame的每一个元素进行操作

    # 对df表中的每一个元素加1
    df.apply(lambda x:x+1)

    applymap()函数用于对DataFrame中的每一个元素执行相同的函数操作。

    # 对df表中的每一个元素加1
    df.applymap(lambda x:x+1)

    在对每个元素进行操作时,上述两个函数等价。

    map()函数

    map(function, args)
    map()函数对序列args中的每个值进行相同的function操作,最终得到一个结果序列。
    x_s = [1, 2, 3]
    y_s = [3, 2, 1]
    
    # 对序列x_s和y_s中的对应元素进行相加
    a = map(lambda x, y:x+y, x_s, y_s)
     
  • 相关阅读:
    Emacs教程
    华为上机测试 2015
    奇偶排序
    C语言中的EOF和回车不一样
    jquery 使用方法
    1116
    1115
    1109
    Oracle14~23
    get与post的区别
  • 原文地址:https://www.cnblogs.com/LLLLgR/p/15027050.html
Copyright © 2011-2022 走看看