【问题标题】:Pandas any/all doesn't seem to return right results熊猫任何/所有似乎都没有返回正确的结果
【发布时间】:2018-10-02 17:49:59
【问题描述】:

我有以下数据框:

test = 

    fa_count    dist_fa_count   dsc_count   dist_dsc_count
       0    63403.285714         1.0          1.0   1.0
       1    37837.285714         1.0          1.0   1.0
       2    9185.285714          1.0          1.0   1.0
       3    23729.142857         1.0          1.0   1.0
       4    22288.142857         1.0          1.0   1.0
       5    77365.000000         1.0          1.0   1.0

我想返回任何值为 != 1 的索引 + 行(即本例中的每一行)。

 test.all(1) == 1

返回所有真和

test.any(1) != 1 

全部返回 false。知道为什么/另一种方式吗?

【问题讨论】:

  • 预期输出是什么?
  • 大概你想要(test == 1).all(1)(test!=1).any(1)这样的东西
  • 是的。就是这样!

标签: python pandas any


【解决方案1】:

你想要类似的东西

(test == 1).all(1) 

(test != 1).any(1)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多