Skip to content Skip to sidebar Skip to footer

.apply() A Bivariate Numpy() Lambda Function To An .expanding() Window Of A Pandas Dataframe

Consider this simple code (numpy.sum in loc_fun is a stand in for a more complicated bivariate function using numpy): import pandas import numpy def loc_fun(A, B): return num

Solution 1:

In lambda x is a numpy.ndarray so You can not refer to column 'A-values' or 'B_values'.

df.expanding(2).apply(lambda x: print(type(x)))

>><class 'numpy.ndarray'>

Post a Comment for ".apply() A Bivariate Numpy() Lambda Function To An .expanding() Window Of A Pandas Dataframe"