I need to group my data frame by two columns and after that count the occurrences of values from third column, which are between 1 and 20.
Data frame:
col1 col2 value
a b 1
a b 3
a b 22
a c 0
a c 3
a c 19
Result:
col1 col2 counter
a b 2
a c 2
My code:
counter = data_frame.groupby(['column1', 'column2'])[((data_frame['value'] >= 1) & (data_frame['value'] < 20))].sum()
Any ideas?