Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to apply a function to multiple columns in pandas dataframe

>>> print df
   A  B  C
0 -1  0  0
1 -4  3 -1
2 -1  0  2
3  0  3  2
4  1 -1  0
>>> print df.applymap(lambda x: x>1)
       A      B      C
0  False  False  False
1  False   True  False
2  False  False   True
3  False   True   True
4  False  False  False
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #apply #function #multiple #columns #pandas #dataframe
ADD COMMENT
Topic
Name
7+4 =