i have a problem with accessing list element in DataFrame:
import pandas as pd
from pandas import DataFrame
d=DataFrame({'pos': {0: [0.11,0.14,0.46], 1:[1,2,3]},'n': {0: 2.0,1:1}})
Column 'pos' contain a list. I need to calculate new column with 'n'-th element of the list in 'pos'-column In this case: 0.46, 2.
I think it would be smth like this:
d[u'new column']=d.pos.apply(lambda x: x[0])
but instead x[0] i need x[d.n].
I read manual and search the forum but havn't found anything. I fill it smth obvious, but i stucked. Help me, please.
def func(x): return next(iter(x.pos.values()))[int(next(iter(x.n.values())))] d['new column']=d.apply(lambda row: func(row), axis=1)