回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我有如下列表和数据框,问题是我想搜索列表中的每个元素,如果它们存在于列中的每个列表中,则添加一个新列并将单词放入新列中。我试过了,但我的解决方案不正确。有人能帮我吗</p>
<pre><code>The List :
list_m = ['KathyConWom',
'monkeyhead78',
'acorncarver',
'bonglez',
'9NewsQueensland',
'paulinedaniels',
'AdvoBarryRoux',
'_sara_jade_',
'theage',
'gaskell_mike',
'saidtarraf',
'BroHilderchump',
'jodyvance',
'COdendahl',
'pfizer',
'RobertKennedyJr',
'Real_Sheezzii',
'Kellie_Martin',
'ThatsOurWaldo',
'SCN_Nkosi',
'azsweetheart013']
</code></pre>
<p>数据帧名称:test</p>
<pre><code> user_id text tweet_id user_name mention
22 1334471712528855040 @KathyConWom @JamesDelingpole Time to stand-up... 1362119551375314948 @KYourrights [KathyConWom, JamesDelingpole]
23 334131548 @KathyConWom @Exp_Sec_Prof It seems like weste... 1362096715877212161 @GowTolson [KathyConWom, Exp]
24 1252182507715526657 @KathyConWom I guess that the hard part would ... 1362096654514552837 @Peterpu52451065 [KathyConWom]
</code></pre>
<p>我想要的是:</p>
<pre><code> user_id text tweet_id user_name mention new_col
22 1334471712528855040 @KathyConWom @JamesDelingpole Time to stand-up... 1362119551375314948 @KYourrights [KathyConWom, JamesDelingpole] KathyConWom
23 334131548 @KathyConWom @Exp_Sec_Prof It seems like weste... 1362096715877212161 @GowTolson [KathyConWom, Exp] KathyConWom
24 1252182507715526657 @KathyConWom I guess that the hard part would ... 1362096654514552837 @Peterpu52451065 [azsweetheart013] azsweetheart013
</code></pre>
<p>我尝试的是:</p>
<pre><code>for index, row in df.iterrows():
for i in list_m:
i in test.mention
test["c"] = i
test
</code></pre>