Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas transform

>>> df = pd.DataFrame({'A': range(3), 'B': range(1, 4)})
>>> df
   A  B
0  0  1
1  1  2
2  2  3
>>> df.transform(lambda x: x + 1)
   A  B
0  1  2
1  2  3
2  3  4
Comment

pandas transform

# 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)]
Comment

PREVIOUS NEXT
Code Example
Python :: make gif from images in python 
Python :: pafy doc 
Python :: math module sin() function in python 
Python :: python how to extract a string from another string 
Python :: is in array python 
Python :: list of dict to dict python 
Python :: confusion matrix 
Python :: lambda in python 
Python :: pandas knn imputer 
Python :: access to specific column array numpy 
Python :: WARNING: This is a development server 
Python :: close a file python 
Python :: is_isogram 
Python :: how to convert pandas price column to integer 
Python :: super title python 
Python :: python divide array into n parts 
Python :: python remove dtype from array 
Python :: python how to inspect pyd for functions 
Python :: Detect Word Then Send Message (discord.py) 
Python :: pandas filter column with or 
Python :: django sessions for beginners 
Python :: How to count the occurrence of certain item in an ndarray? 
Python :: python try catch print stack 
Python :: exponential python 
Python :: how to get the number of rows and columns in a numpy array 
Python :: python not in list 
Python :: updateview 
Python :: concatenate list 
Python :: django exclude queryset 
Python :: check if object is array like python 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =