I have two pandas DataFrames with the same DateTime index.
The first one is J:
A B C
01/01/10 100 400 200
01/02/10 300 200 400
01/03/10 200 100 300
The second one is K:
100 200 300 400
01/01/10 0.05 -0.42 0.61 -0.12
01/02/10 -0.23 0.11 0.82 0.34
01/03/10 -0.55 0.24 -0.01 -0.73
I would like to use J to reference K and create a third DataFrame L that looks like:
A B C
01/01/10 0.05 -0.12 -0.42
01/02/10 0.82 0.11 0.34
01/03/10 0.24 -0.55 -0.01
To do so, I need to take each value in J and look up the corresponding value in K where the column name is that value for the same date.
I tried to do:
L = J.apply( lambda x: K.loc[ x.index, x ], axis='index' )
but get:
ValueError: If using all scalar values, you must pass an index
I would ideally like to use this so that any NaN values contained in J will remain as is, and will not be looked up in K. I had unsuccessfully tried this:
L = J.apply( lambda x: np.nan if np.isnan( x.astype( float ) ) else K.loc[ x.index, x ] )