Pandas: How to split row of sentences with list values for each row on other column?

I have a Pandas Dataframe like this:

     id             data                             label                              
    1336    'The PARTIES are willing to hold'     [1, 11, label_1]  
    1336    'The PARTIES are willing to hold'     [12, 15, label_2]

I would like to split each data row thanks to informations in list of label column. For example, for the first row I would like to keep only the characters of data from first to 11 (‘The PARTIES’) and create a column ‘label’ corresponding to the last element of the list.

Expected output:

         id             data      label                             
        1336    'The PARTIES'   label_1 
        1336    'are wi'        label_2

Answer

You can apply a custom function on data column using label column information:

extract_lbl = lambda x: (x['data'][x['label'][0]:x['label'][1]+1], x['label'][2])
df[['data', 'label']] = df.apply(extract_lbl, axis=1, result_type='expand')

Output:

>>> df
     id         data    label
0  1336  The PARTIES  label_1
1  1336          are  label_2