我有两个数据帧,我们称它们为df1和df2
df1型
Term Served
term1 82321
term2 54232
term3 34323
term4 1231
df2型
Full Term clicks
this is term1 233
oh boy this is term2 122
yea that's right term1 1121
oh no not that term4 313123
我想逐行查找每一次df1中的术语出现在df2中。在那之后,我想为那个特定的术语加上所有的点击次数。结果会是
Term Served Clicks
term1 82321 1354
term2 54232 122
term3 34323 0
term4 1231 313123
这是我到目前为止的情况。我还没有抓住df1中的术语出现在df2中的所有时间。下面的代码只在df1的第一行中循环。也许我不理解str.findall()
或者我的循环错了
for index, row in df1.iterrows():
for row2 in df2.iteritems():
full_headline = df2['Full Term'].str.findall(row[0])
print(full_headline)
IIUC使用
str.findall
从df1中提取df2中的项,然后我们需要gourpby
sum
df2中的公共项。到目前为止,我们只需要使用map
将结果分配回df1如果您希望在
str.findall
之后看到unnesting,请更新相关问题 更多 >
编程相关推荐