Python pandas apply 將函數應用到各行和各列
環境信息

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
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小時內刪除侵權內容。
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。