Search code examples
pythondataframelistindexingrow

using python looking for values in a column from a list


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"


Solution

  • This is how I solve it:

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