我有数据帧
site1 time1 site2 time2 site3 time3 site4 time4 site5 time5 ... time6 site7 time7 site8 time8 site9 time9 site10 time10 target
session_id
21669 56 2013-01-12 08:05:57 55.0 2013-01-12 08:05:57 NaN NaT NaN NaT NaN NaT ... NaT NaN NaT NaN NaT NaN NaT NaN NaT 0
54843 56 2013-01-12 08:37:23 55.0 2013-01-12 08:37:23 56.0 2013-01-12 09:07:07 55.0 2013-01-12 09:07:09 NaN NaT ... NaT NaN NaT NaN NaT NaN NaT NaN NaT 0
77292 946 2013-01-12 08:50:13 946.0 2013-01-12 08:50:14 951.0 2013-01-12 08:50:15 946.0 2013-01-12 08:50:15 946.0 2013-01-12 08:50:16 ... 2013-01-12 08:50:16 948.0 2013-01-12 08:50:16 784.0 2013-01-12 08:50:16 949.0 2013-01-12 08:50:17 946.0 2013-01-12 08:50:17 0
114021 945 2013-01-12 08:50:17 948.0 2013-01-12 08:50:17 949.0 2013-01-12 08:50:18 948.0 2013-01-12 08:50:18 945.0 2013-01-12 08:50:18 ... 2013-01-12 08:50:18 947.0 2013-01-12 08:50:19 945.0 2013-01-12 08:50:19 946.0 2013-01-12 08:50:19 946.0 2013-01-12 08:50:20 0
我需要计算N列,其中站点!=楠。 我试着用
df[['site%s' % i for i in range(1, 11)]].count(axis=1)
但每一个身份证都会给我10个
我也试过了
train_df[sites].notnull().count(axis=1)
这也没用
期望输出
21669 2
54843 4
77292 10
114021 10
我只需要
count
就可以做到这一点:count
专门统计非空值。当前实现的问题是notnull
产生布尔值,并且bool
肯定不是null,这意味着它们总是被计数而且
按行查找缺失值的简单方法是:
要查找具有3个以上空值的行数,请执行以下操作:
如果需要删除具有3个以上空值的行,则可以遵循以下代码:
同样,用{}换{}也应该可以做到这一点
相关问题 更多 >
编程相关推荐