Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

How to select rows in a DataFrame between two values, in Python Pandas?

df = df[df['closing_price'].between(99, 101)]
#OR
df = (
      df[
        (df['closing_price'] >= 99) & 
        (df['closing_price'] <= 101)
        ]
     )
#OR
df.query('99 <= closing_price <= 101')
#OR
 df.query('closing_price.between(99, 101, inclusive=True)', engine="python") 
#- but this will be slower compared to "numexpr" engine.
#OR
newdf = df.query('closing_price.mean() <= closing_price <= closing_price.std()')
#OR
mean = closing_price.mean()
std = closing_price.std()
newdf = df.query('@mean <= closing_price <= @std')
#OR
df = df[(99 <= df['closing_price'] <= 101)]


Comment

PREVIOUS NEXT
Code Example
Python :: save_img keras 
Python :: remove last line of text file python 
Python :: how to display csv in pandas 
Python :: python from float to decimal 
Python :: python access global variable 
Python :: concat columns pandas dataframe 
Python :: python web parse 
Python :: pyside 
Python :: change strings in a list to uppercase 
Python :: debug mode: on flask pythin window 
Python :: hex to rgb python 
Python :: redis json python 
Python :: pil img to pdf 
Python :: how to change size of turtle in python 
Python :: apply lambda with if 
Python :: np.percentile 
Python :: python find duplicates in string 
Python :: pandas select rows by multiple conditions 
Python :: scipy cosine distance 
Python :: python flatten list 
Python :: python tuple vs list 
Python :: pyton filter 
Python :: what does int do in python 
Python :: requests.Session() proxies 
Python :: matplotlib dateformatter x axis 
Python :: python delete from list 
Python :: good python ide 
Python :: pandas get value not equal to 
Python :: python if any element in string 
Python :: Python How To Check Operating System 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =