【问题标题】:Pandas multiple conditions filtering with or statementPandas 使用 or 语句过滤多个条件
【发布时间】:2021-11-04 15:47:15
【问题描述】:

看看是否有人知道如何在 pandas 中链接多个条件......我正在寻找这样的形式:

df[(df.col1>2)&df.col2<5) or (df.col5==5)&(df.col3>=78)]

到目前为止,我还没有找到允许我在示例中包含 or 条件的解决方案。

感谢任何帮助 1

【问题讨论】:

标签: python pandas dataframe conditional-statements filtering


【解决方案1】:

和有一个字符一样,所以使用或使用 | for or 声明 有时熊猫更喜欢()

df[((df.col1>2)&df.col2<5)) | ((df.col5==5)&(df.col3>=78))]

【讨论】:

    猜你喜欢
    • 2015-06-10
    • 1970-01-01
    • 2018-12-25
    • 1970-01-01
    • 2019-03-01
    • 2021-09-01
    • 1970-01-01
    • 2017-06-24
    相关资源
    最近更新 更多