如何通过使用查询删除行

时间:2018-12-09 10:38:42

标签: python pandas

我正在尝试根据查询结果删除行,但这给了我这个错误

  df2.drop(df.query('group == "treatment" and landing_page !="new_page" or group != "treatment" and landing_page =="new_page"'),axis=1)

显示的错误是

ValueError: labels ['user_id' 'timestamp' 'group' 'landing_page' 'converted'] not contained in axis

1 个答案:

答案 0 :(得分:0)

index输出中的queryaxis=0一起用于以下行:

df2.drop(df.query('group == "treatment" and landing_page !="new_page" or group != "treatment" and landing_page =="new_page"').index, axis=0)