Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python pandas dataframe conditional subset

In [722]: df[(df['C']==1) | df['B']]
Out[722]:
   A      B  C
0  1   True  1
2  2  False  1
3  2   True  2
4  3   True  1

In [723]: df.query('C==1 or B==True')
Out[723]:
   A      B  C
0  1   True  1
2  2  False  1
3  2   True  2
4  3   True  1

In [724]: df[df.eval('C==1 or B==True')]
Out[724]:
   A      B  C
0  1   True  1
2  2  False  1
3  2   True  2
4  3   True  1
Comment

PREVIOUS NEXT
Code Example
Python :: python latest version 64 bit 
Python :: hierarchy dendrogram 
Python :: how to print a value of a key in nested dictionary python 
Python :: python load file with multiple jsons 
Python :: sorted python 
Python :: python write a line to a file 
Python :: count items in list python by loop 
Python :: max python 
Python :: false in py 
Python :: python remove first item in list 
Python :: python get parent class 
Python :: pandas replace multiple values in column 
Python :: how to devided array into parts python 
Python :: convert list to dataset python 
Python :: how to save plot in matplotlib 
Python :: python repr vs str 
Python :: copy array along axis numpy 
Python :: python set split limit 
Python :: flask multuple parameters 
Python :: random.randint(0,20) + pyrthon 
Python :: python string: .format() 
Python :: django raw without sql injection 
Python :: pandas find fifth caracter in field and change cell based on that number 
Python :: python codes for counting the occurrence of a letters in dictionary excluding digits 
Python :: select element using Css selector in python 
Python :: circular dependencies in python 
Python :: python all but the last element 
Python :: standard noramlization 
Python :: import from parent directory python 
Python :: Python DateTime Class Syntax 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =