擅长:python、mysql、java
<p>您还可以使用<a href="https://numpy.org/doc/stable/reference/generated/numpy.intersect1d.html" rel="nofollow noreferrer">^{<cd1>}</a>以列表格式获取唯一的<strong>交叉点</strong>,如下所示:</p>
<pre><code>import numpy as np
df['new_col'] = df['mention'].map(lambda x: np.intersect1d(x, list_m))
</code></pre>
<p>如果要将列表转换为逗号分隔的字符串,只需将其与<a href="https://pandas.pydata.org/docs/reference/api/pandas.Series.str.join.html" rel="nofollow noreferrer">^{<cd2>}</a>链接,如下所示:</p>
<pre><code>import numpy as np
df['new_col'] = df['mention'].map(lambda x: np.intersect1d(x, list_m)).str.join(', ')
</code></pre>
<p>您也可以在<a href="https://pandas.pydata.org/docs/reference/api/pandas.Series.apply.html" rel="nofollow noreferrer">^{<cd3>}</a>中简单地使用列表理解,如下所示:</p>
<pre><code>df['new_col'] = df['mention'].apply(lambda x: [y for y in x if y in list_m]).str.join(', ')
</code></pre>