I have a multi-index frame dfu:
open high low close
Date Time
2016-11-28 09:43:00 26.03 26.03 26.030 26.030
09:48:00 25.90 25.90 25.760 25.760
09:51:00 26.00 26.00 25.985 25.985
2016-11-29 09:30:00 24.98 24.98 24.98 24.9800
09:33:00 25.00 25.00 24.99 24.9900
09:35:00 25.33 25.46 25.33 25.4147
I would like to create a new column ['closeScaled'], which is calculated by executing the foo function, using the first row of the current level value = 0 from the column ['open'] and the current row ['close'] as arguments. I suspect the solution will include something like:
dfu['closeScaled']=dfu.apply(lambda x: foo(*get first row of current date*[0],x[3]))
I just can't figure out how to get the first row of the current level = 0.
if foo:
def foo(firstOpen,currentClose):
return (currentClose / firstOpen)
then I would expect the column closeScaledto contain (trimming to 4 decimal places):
open high low close closeScaled
Date Time
2016-11-28 09:43:00 26.03 26.03 26.030 26.030 1.0000
09:48:00 25.90 25.90 25.760 25.760 0.9896
09:51:00 26.00 26.00 25.985 25.985 0.9982
2016-11-29 09:30:00 24.98 24.98 24.98 24.9800 1.0000
09:33:00 25.00 25.00 24.99 24.9900 1.0004
09:35:00 25.33 25.46 25.33 25.4147 1.0174