Pandas Dataframe.lookup
is there a decent example how to use Pandas DataFrame.lookup Yes I saw this but not sure what's the point... it seems it's just selecting the price column: vectorized-look-up-of-va
Solution 1:
Expected output was included in the order
dataframe of the original post , you can assuming there is noprice
column in order , if so using lookup
is a nice way for get that value
orders['price']= prices.lookup(orders.Date, orders.ticker)
Also you can using loc
or for loop here
orders.apply(lambda x : prices.loc[x['Date'],x['ticker']],axis=1)
Out[116]:
0339.441342.642143.923616.50479.46579.686609.567158.738160.979167.8410323.0311606.7712606.7713392.46
dtype: float64
[prices.loc[x,y] for x , y inzip(orders.Date,orders.ticker)]
Out[118]:
[339.44,
342.64,
143.92,
616.5,
79.46,
79.68,
609.56,
158.73,
160.97,
167.84,
323.03,
606.77,
606.77,
392.46]
Post a Comment for "Pandas Dataframe.lookup"