Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

pandas transform vs filter

# when used with groupby, transform is faster than filter
# use transform instead of filter e.g.
df = df[(df.groupby('col1')['col2'].transform('sum')>=200) 
        & (df.groupby('col1')['col3'].transform('nunique')>=20)]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #pandas #transform #filter
ADD COMMENT
Topic
Name
2+9 =