使用Python从列表中查找列中的值。

huangapple go评论68阅读模式
英文:

using python looking for values in a column from a list

问题

我有一个包含3个不同代码的列表,我需要在数据框的某一列的每一行中进行检查。如果列表中的每个代码都与数据框列中的值匹配,如果匹配,则需要在不同的列中填写"YES":(使用Python)

for l in dlist:
    for index, row in yes_marketo.iterrows():
        if row['Entry Point List'] == l:
            yes_marketo.at[index, "Marketo DEP"] = "YES"
        else:
            pass

但即使它们不匹配,它也会填充为"YES"。

英文:

I have a list with 3 different codes and I need to check in every row of a column from a dataframe. If every code in the list matches with the value in the dataframe column, if it does, I need to fill "YES" in a different column: (using python)

for l in dlist:
    for index, row in yes_marketo.iterrows():
        if row['Entry Point List'] == l:
            yes_marketo.at[index, "Marketo DEP"] = "YES"
        else:
            pass

But even if they don't match, it's filling with "YES"

答案1

得分: 1

我不认为你可以像你上面那样比较两行,你可能需要这样做一些事情:

if row[0] == l[0] and row[1] == l[1] and row[2] == l[2]:

另外,你可能需要对一些值进行类型转换。

英文:

I don't think you can compare two rows like you did above, you may need to do some thing like this:

if row[0] == l[0] and row[1] == l[1] and row[2] == l[2]:

also you may need typecasting on some values

答案2

得分: 0

这是我解决的方式:

for l in dlist:
    mask = yes_marketo['Entry Point List'] == l
    yes_marketo.loc[mask, 'Marketo DEP'] = 'YES'
英文:

This is how I solve it:

for l in dlist:
    mask = yes_marketo['Entry Point List'] == l
    yes_marketo.loc[mask, 'Marketo DEP'] = 'YES'

huangapple
  • 本文由 发表于 2023年7月17日 12:17:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76701465.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定