Given the Following DataFrames
jg
Job Group
1 116.0
2 116.0
3 116.0
4 116.0
5 116.0
6 116.0
7 124.0
8 124.0
9 74.0
10 74.0
11 74.0
12 126.0
13 126.0
ul
UpperGroup LowerGroup Time
116 116 5
116 124 15
116 74 15
116 126 15
124 116 15
124 124 5
124 74 15
124 126 15
74 116 15
74 124 15
74 74 5
74 126 15
126 116 15
126 124 15
126 74 15
126 126 5
Desired Result
- The following table is produced with an Excel
vlookup
- The colors are for reference
- The Grey filled area isn't needed in the DataFrame result
- I'm trying to create a DataFrame / Table where the
'Job' numbers from jg are the column and the index.
- The
'Group' value for the 'Job' number in the columns, should be used to reference 'UpperGroup' from ul
- The
'Group' value for the 'Job' number in the index, should be used to reference 'LowerGroup' from ul
- The values are
'Time' from ul corresponding to 'UpperGroup' and 'LowerGroup'.
'UpperGroup' = 116 and 'LowerGroup' = 224, map to 'Time' = 15

Reproducible DataFrames
import pandas as pd
ul_data = {'UpperGroup': [116, 116, 116, 116, 124, 124, 124, 124, 74, 74, 74, 74, 126, 126, 126, 126],
'LowerGroup': [116, 124, 74, 126, 116, 124, 74, 126, 116, 124, 74, 126, 116, 124, 74, 126],
'Time': [5, 15, 15, 15, 15, 5, 15, 15, 15, 15, 5, 15, 15, 15, 15, 5]}
ul = pd.DataFrame(ul_data)
jg_data = {'Job': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
'Group': [116.0, 116.0, 116.0, 116.0, 116.0, 116.0, 124.0, 124.0, 74.0, 74.0, 74.0, 126.0, 126.0]}
jg = pd.DataFrame(jg_data)
Research
- I have reviewed several of the questions from the search, but they don't really seem to fit, and I just can't think of a way to bring it all together.
- Google - pandas vlookup site:stackoverflow.com
- Considered
merge/join
- Considered
map