英文:
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'
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论