I have a source dataframe
source.head()
Out[41]:
A B C compare
892 4.031250 6.218750 6.515625 4.246094
893 4.079531 6.222656 5.945312 4.038281
894 4.023438 6.226562 6.039062 4.250000
895 5.109531 4.238281 6.035156 4.038281
896 4.019531 6.242188 6.089844 4.242188
and a target dataframe with same index
target.tail()
Out[42]:
A B C
636893 0 0 0
636894 0 0 0
636895 0 0 0
636896 0 0 0
636897 0 0 0
I want to do this-
in source, select
a. index where 'compare' is less than min of the rest. b. the column of the min of the restin target, update that location (index and column) with source['compare']/source[min_col]
So with the above source values, the result of the target would be this
target.head()
Out[41]:
A B C
892 0 0 0
893 4.038281/4.079531 0 0
894 0 0 0
895 0 4.038281/4.238281 0
896 0 0 0
I do 1a. i.e. selecting index where compare less than min of the rest by:
tenors = ['A', 'B', 'C']
idx_select= source.index[(source['compare'] < source[tenors].min(1))]
I can do 1b. i.e. get the column where min occurs by:
col_min = source.ix[idx_select, tenors].idxmin(1)
I am not sure how to the second step, i.e. update target values except doing a loop by rows.
Any suggestions to avoid loops?