Skip to content Skip to sidebar Skip to footer

Python Pandas: Function Doesn't Work When Used With Apply()

The following function: def func(x): for k in x['slices']: for j in k: print(x['low'].iloc[j]) applied in the following manner works: func(test) but as f

Solution 1:

define your function this way

def fun(slices):
    return [df.low.loc[s].tolist() for s in slices]

And apply over the slices column

df['slices_low'] = df.slices.apply(fun)

df

enter image description here

Post a Comment for "Python Pandas: Function Doesn't Work When Used With Apply()"