I have two pandas dataframes; buffers_slots
and slots_vessels
Both contain only zeros and ones as data.
I'm working on a vessel assignment problem where a number of vessels are selected and used to prepare a number of buffers.
The link between buffers and vessels are notional "slots".
The buffers_slots
dataframe tells me which slot each buffer is prepared in.
In it, each row sums to one, i.e. each buffer is made in only one slot.
>>> buffers_slots
5 7 8
Buffer #24 0.0 0.0 1.0
Buffer #25 1.0 0.0 0.0
Buffer #26 1.0 0.0 0.0
Buffer #27 0.0 0.0 1.0
Buffer #28 0.0 1.0 0.0
Buffer #29 0.0 1.0 0.0
The slots_vessels dataframe tells me which size vessel is in a given slot (it is possible to have empty slots - i.e. each row sums to either 0 or 1. It is also possible to use the same size vessel in more than one slot - i.e. each column may sum to 0, 1 or more than one).
>>> slots_vessels
1000 L 2000 L 3000 L 4000 L 5000 L 6000 L 7000 L 8000 L
0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
1 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
2 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
3 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
5 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0
6 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
7 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0
8 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0
I essentially want to use the slots_vessels
dataframe to translate the column names in the buffers_slots
dataframe, i.e. replacing 5, 7, 8 with '2000 L', '7000 L' and '4000 L' respectively, giving the following output:
>>> buffers_vessels
2000 L 7000 L 4000 L
Buffer #24 0.0 0.0 1.0
Buffer #25 1.0 0.0 0.0
Buffer #26 1.0 0.0 0.0
Buffer #27 0.0 0.0 1.0
Buffer #28 0.0 1.0 0.0
Buffer #29 0.0 1.0 0.0
I'm thinking the solution may involve creating a dict mapping slots to vessels, i.e. something like:
>>> slots
{0: None, 1: None, 2: None, 3: None, 4: None, 5: '2000 L', 6: None, 7: '7000 L', 8: '4000 L'}
...but I'm not sure how to create such a dict.
Alternatively, is there some neat way of mapping/translating to achieve my goal?