擅长:python、mysql、java
<p>以下是成功的秘诀:</p>
<pre><code>slots = dict(slots_vessels.T.idxmax())
buffers_vessels = buffers_slots.rename(slots, axis='columns')
</code></pre>
<p>输出:</p>
<pre><code>>>> slots
{0: '1000 L', 1: '1000 L', 2: '1000 L', 3: '2000 L', 4: '1000 L', 5: '1000 L', 6: '1000 L', 7: '7000 L', 8: '4000 L'}
>>> 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
</code></pre>
<p>插槽dict中的值有点误导,因为它表示每个空插槽中都有一个1000升的容器,但由于我们对空插槽不感兴趣,因此没有执行此错误。
如果存在这样一个函数来创建OP中所示的<code>slots</code>dict,那么最好用“where equal to 1”函数替换<code>idxmax</code>函数</p>