通过pandas在不同列上应用条件来过滤数据框

时间:2021-01-23 18:29:38

标签: pandas

我正在寻找一种通过以下条件过滤 df 的方法:

created_by 列中的值等于 owner 列中的值且 status 等于 'Active'

enter image description here

2 个答案:

答案 0 :(得分:0)

解决方案:

(df['created_by']==df['owner']) & (df['status']=='Active')

并请阅读用户指南:Indexing and selecting data

答案 1 :(得分:0)

您要实现的条件的逻辑是,您要过滤其 created_by 值与其所有者值不同且状态应为活动的所有行。

if ((customers_df["created_by"] == customers_df["owner"]) & (customers_df["status"] == "Active")):
    # do your  Business logic