<ul>
<li>给定<code>df1</code>和<code>df2</code>如下:</li>
</ul>
<h2><code>df1</code></h2>
<pre class="lang-py prettyprint-override"><code>| | Line | TagName | CLASS |
| -:|: -|: | :|
| 0 | PT_WOA | .ZS01_LA120_T05.SB.S2384_LesSwL | 10 |
| 1 | PT_WOA | .ZS01_RB2202_T05.SB.S2385_FLOK | 10 |
| 2 | PT_WOA | .ZS01_LA120_T05.SB._CBAbsHy | 10 |
| 3 | PT_WOA | .ZS01_LA120_T05.SB.S3110_CBAPV | 10 |
| 4 | PT_WOA | .ZS01_LARB2204.SB.S3111_CBRelHy | 10 |
</code></pre>
<h2><code>df2</code></h2>
<pre class="lang-py prettyprint-override"><code>| | EquipmentNo | EquipmentDescription | Equipment |
| -:| :|: -|: |
| 0 | 1311256 | Lifting table | LA120 |
| 1 | 1311257 | Roller bed | RB2200 |
| 2 | 1311258 | Lifting table | LT2202 |
| 3 | 1311259 | Roller bed | RB2202 |
| 4 | 1311260 | Roller bed | RB2204 |
</code></pre>
<ol>
<li>在<code>df2</code>中的<code>Equipment</code>中查找唯一的<code>equipment</code></li>
</ol>
<pre class="lang-py prettyprint-override"><code>equipment = df2.Equipment.unique().tolist()
</code></pre>
<ol start=“2”>
<li>通过在<code>equipment</code>中查找匹配项,在<code>df1</code>中创建<code>Equipment</code>列</li>
</ol>
<pre class="lang-py prettyprint-override"><code>df1['Equipment'] = df1['TagName'].apply(lambda x: ''.join([part for part in equipment if part in x]))
</code></pre>
<ol start=“3”>
<li>在<code>Equipment</code>上合并成最终形式
<ul>
<li>如果不希望在<code>df_final</code>中使用<code>Equipment</code>列,请将<code>.drop(columns=['Equipment'])</code>添加到下一行代码的末尾</李>
</ul></li>
</ol>
<pre class="lang-py prettyprint-override"><code>df_final = df1[['Line', 'TagName', 'Equipment']].merge(df2, on='Equipment')
</code></pre>
<h2><code>df_final</code></h2>
<pre class="lang-py prettyprint-override"><code>| | Line | TagName | Equipment | EquipmentNo | EquipmentDescription |
| -:|: -|: |: | :|: -|
| 0 | PT_WOA | .ZS01_LA120_T05.SB.S2384_LesSwL | LA120 | 1311256 | Lifting table |
| 1 | PT_WOA | .ZS01_LA120_T05.SB._CBAbsHy | LA120 | 1311256 | Lifting table |
| 2 | PT_WOA | .ZS01_LA120_T05.SB.S3110_CBAPV | LA120 | 1311256 | Lifting table |
| 3 | PT_WOA | .ZS01_RB2202_T05.SB.S2385_FLOK | RB2202 | 1311259 | Roller bed |
| 4 | PT_WOA | .ZS01_LARB2204.SB.S3111_CBRelHy | RB2204 | 1311260 | Roller bed |
</code></pre>