I have 3 pandas multiindex column dataframes
dataframe 1(minimum value):
| A | B | C |
| Min | Min | Min |
|-------|-------|------|
0 | 26.47 | 17.31 | 1.26 |
1 | 27.23 | 14.38 | 1.36 |
2 | 27.23 | 18.88 | 1.28 |
dataframe 2 (value used to compare with)
row 0, row 1 and row 2 are the same, I extend the dataframe to three row for comparison with min and max dataframe. Value in each dataframe cell is ndarray
| A | B | C |
| Val | Val | Val |
|---------------------|-----------------------|--------------------|
0 | [27.58,28.37,28.73] | [17.31, 18.42, 18.72] | [1.36, 1.28, 1.27] |
1 | [27.58,28.37,28.73] | [17.31, 18.42, 18.72] | [1.36, 1.28, 1.27] |
2 | [27.58,28.37,28.73] | [17.31, 18.42, 18.72] | [1.36, 1.28, 1.27] |
dataframe 3(maximum value):
| A | B | C |
| Max | Max | Max |
|-------|-------|------|
0 | 28.68 | 18.42 | 1.37 |
1 | 29.50 | 17.31 | 1.47 |
2 | 29.87 | 20.45 | 1.39 |
Expected result:
| A | B | C |
| Result | Result | Result |
|---------------------|-----------------------|----------------------|
0 | [True, True, False] | [True, True, False] | [True, True, True] |
1 | [True, True, True] | [True, False, False] | [True, False, False] |
2 | [True, True, True] | [False, False, False] | [True, True, False] |
I'd like to perform element wise comparison in this way:
min <= each element in ndarray <= max
i.e
for row 0:
26.47 <= [27.58,28.37,28.73] <= 28.68
17.31 <= [17.31, 18.42, 18.72] <= 18.42
1.26 <= [1.36, 1.28, 1.27] <= 1.37
and so on
I tried ( datafram2 >= dataframe3 ) & ( datafram2 <= datafram3 ) but not work.
What's the simplest way and fastest way to compute the result?
Example dataframe code:
min_columns = pd.MultiIndex.from_product( [ [ 'A', 'B', 'C' ], [ 'Min' ] ] )
val_columns = pd.MultiIndex.from_product( [ [ 'A', 'B', 'C' ], [ 'Val' ] ] )
max_columns = pd.MultiIndex.from_product( [ [ 'A', 'B', 'C' ], [ 'Max' ] ] )
min_df = pd.DataFrame( [ [ 26.47, 17.31, 1.26 ], [ 27.23, 14.38, 1.36 ], [ 27.23, 18.88, 1.28 ] ], columns=min_columns )
val_df = pd.DataFrame( [ [ [ 27.58, 28.37, 28.73 ], [ 17.31, 18.42, 18.72], [1.36, 1.28, 1.27 ] ] ] , columns=val_columns )
max_df = pd.DataFrame( [ [ 28.68, 18.42, 1.37 ], [ 29.50, 17.31, 1.47 ], [ 29.87, 20.45, 1.39 ] ] , columns=max_columns )