df.assign(result_col=df.col4.eq(3).astype(int)).groupby(['col1', 'col2']).agg(
    dict(col3='size', col4='nunique', result_col='sum'))
How to do group by and take count of unique and count of some value as aggregate on same column in python pandas?