MulDataFrame.call#
- MulDataFrame.call(func, *args, **kwargs)#
Apply a function to the values dataframe and returns the result as a scalar, a MulSeries or a MulDataFrame with the index and the columns dataframes properly arranged.
Parameters:#
- funcfunction or str
A function applied to the values dataframe of the MulDataFrame. The function should return a scalar, a pandas Series or a pandas DataFrame.
If a DataFrame is returned, its index and columns must be the same as the primary index and columns (order can be different if there are no duplicate values in the primary index and columns).
If a Series is returned, its index must be the same as either the primary index or the primary columns (same requirement as above). If the primary index and columns are the same, explicitly pass an
axisargument to the function to determine the direction in which the funciton is applied to the values dataframe.If
funcis a string, it must be a valid method name ofpandas.DataFrame. The method should saftisfy the same requirement as above.
- *argspositional arguments to the function
The MulDataFrame is the 1st positional argument to the function. *args are from the 2nd positional argument onwards.
- **kwargskeyword arguments to the function
keyword arguments to the function.
Returns#
- scalar, MulSeries or MulDataFrame
If the return value is a MulDataFrame, it should have the same index and columns dataframes as the caller. If the return values is a MulSeries, its index dataframe should be the same as either the caller’s index dataframe or its columns dataframe.
Examples#
>>> import pandas as pd >>> import muldataframe as md >>> import numpy as np >>> index = pd.DataFrame([[1,2],[3,6],[5,6]], index=['a','b','b'], columns=['x','y']) >>> columns = pd.DataFrame([[5,7],[3,6]], index=['c','d'], columns=['f','g']) >>> mf = md.MulDataFrame([[1,3],[8,9],[9,10]],index=index,columns=columns) >>> mf.call(np.power,2) (3, 2) g 7 6 f 5 3 c d -------- ---------- x y c d a 1 2 a 1 9 b 3 6 b 64 81 b 5 6 b 64 100
MulDataFrame