Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

pandas transform count where condition

# use lambda function within your transform. 
# here i am checking if key3 is greater than 0
df.groupby(['key1', 'key2'])['key3'].transform(lambda x: x[x > 0].count())
 
PREVIOUS NEXT
Tagged: #pandas #transform #count #condition
ADD COMMENT
Topic
Name
7+5 =