Parameters: func : function.Function to apply to each column or row. axis : {0 or ‘index’, 1 or ‘columns’}, default 0 Axis along which the function is applied: 0 or ‘index’: apply function to each column. 1 or ‘columns’: apply function to each row.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
>>> df = pd.DataFrame([[4, 9],] * 3, columns=['A', 'B']) >>> df A B 049 149 249 >>> df.apply(np.sum, axis=0) A 12 B 27 dtype: int64 >>> df.apply(np.sum, axis=1) 013 113 213 dtype: int64