Conditionally count values in a pandas groupby object

Viewed 3877

I have a pandas.core.groupby.DataFrameGroupBy object where I am trying to count the number of rows where a value for TOTAL_FLOOR_AREA is > 30. I can count the number of rows for each dataframe in the groupby object using:

import numpy as np

grouped = master_lsoa.groupby('lsoa11')

grouped.aggregate(np.count_nonzero).TOTAL_FLOOR_AREA

But how do I conditionally count rows where the value for TOTAL_FLOOR_AREA is greater than 30?

Sam

2 Answers
Related