【问题标题】:Find out the sum of the null values for an attributes depending upon class values in pandas根据 pandas 中的类值找出属性的空值总和
【发布时间】:2022-07-27 00:13:22
【问题描述】:

数据集看起来像

 class       subject   computer_buy(class)
 Junior      Science   Yes
 Sophomore   Science   Yes
 Senior      Economics No
 Junior       ?        No
 Senior      Arts      No

假设数据集的名称是 toy_data。我想知道有多少?类值No

我写了一个这样的查询

   toy_data['subject'].isnull().sum()[toy_data['computer_buy']=='No']

上述查询的错误

IndexError: 标量变量的索引无效。

查询的正确方法应该是什么?

谢谢。

【问题讨论】:

    标签: python pandas classification


    【解决方案1】:

    IIUC,你可以用

    ((toy_data['computer_buy']=='No') & (toy_data['subject'] == '?')).sum()
    

    【讨论】:

      猜你喜欢
      • 2017-06-02
      • 2014-10-31
      • 1970-01-01
      • 1970-01-01
      • 2016-11-12
      • 1970-01-01
      • 1970-01-01
      • 2023-01-19
      • 1970-01-01
      相关资源
      最近更新 更多