Skip to content Skip to sidebar Skip to footer

Python Pandas: Table Manipulation With Slices As Variables

I have a table such as follow (in black). I would like to create an additional column such as visible in red, to the right. Basically for each slice variable in the 'slice' column,

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: Table Manipulation With Slices As Variables"