Python pandas apply 将函数应用到各行和各列

网友投稿 673 2022-05-30

环境信息

ModelArts

Notebook - pytorch1.4-cuda10.1-cudnn7-ubuntu18.04

JupyterLab - Notebook - Conda-python3

Pandas apply 将函数应用到各行和各列

import pandas as pd import numpy as np

df = pd.DataFrame(np.arange(9).reshape(3,3),columns=list("ABC")) df

df.apply(lambda x:x.sum()) A 9 B 12 C 15 dtype: int64

Python pandas apply 将函数应用到各行和各列

df.apply(lambda x:x.sum(),axis=1) 0 3 1 12 2 21 dtype: int64

help

help(df.apply) Help on method apply in module pandas.core.frame: apply(func, axis=0, raw=False, result_type=None, args=(), **kwds) method of pandas.core.frame.DataFrame instance 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. ......

相关链接

Python入门篇

Python进阶篇

Python应用篇

帮助文档-AI开发平台ModelArts

【生长吧!Python】有奖征文火热进行中

备注

欢迎各位同学一起来交流学习心得^_^

在线课程、沙箱实验、认证、论坛和直播,其中包含了许多优质的内容,推荐了解与学习。

Python

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:【讨论】瀑布模式有什么不足?
下一篇:JS:dom-to-image网页截图保存
相关文章