You can use shape
:
a = data[data['cond'] == 1].shape[0]
I use time and it seems that both options are the same in large df
(length 60k
):
In [1399]: %timeit data[data['fld1'] == 1].shape[0]
100 loops, best of 3: 4.9 ms per loop
In [1400]: %timeit len(data[data['fld1'] == 1])
100 loops, best of 3: 4.91 ms per loop
source
share