I have a pandas dataframe with two columns:
df.selection
(...)
1454 5
1458 6
1473 4
1474 4
1487 4
1491 3
1500 6
Name: selection, Length: 117, dtype: int64
and
df.value_lsts
(...)
1454 [8.4, 16.0, 7.4, 3.96, 17.5, 2.6]
1458 [8.85, 3.25, 5.3, 4.95, 8.14, 11.0]
1473 [9.8, 5.28, 11.67, 15.15, 4.47, 3.06]
1474 [5.5, 2.19, 7.7, 11.98, 28.0, 8.54]
1487 [26.6, 9.74, 7.71, 6.46, 2.28, 7.58]
1491 [6.4, 3.1, 19.92, 4.2, 6.37, 11.05]
1500 [3.0, 22.91, 8.61, 13.58, 6.37, 3.69]
Name: value_lsts, Length: 117, dtype: object
That is a column of lists.
What I need is to create another column which value will be the given by:
value_lsts[df.selection - 1]
For example for row 1500 we have
df.value_lsts
1500 [3.0, 22.91, 8.61, 13.58, 6.37, 3.69]
df.selection
1500 6
so the return value would be 3.69
I have tried everything but could not come up with a solution. What is the pythonic way of accessing the correct index through the df.selection column ?
Thank you very much. Piero