Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas filter on range of values

import pandas as pd

#initialize dataframe
df = pd.DataFrame({'a': [2, 4, 8, 5], 'b': [2, 0, 9, 7]})

#check if the values of df['a'] are in the range(3,6)
out = df['a'].isin(range(3,6))

#filter dataframe
filtered_df = df[out]

print('Original DataFrame
-------------------
',df)
print('
Filtered DataFrame
-------------------
',filtered_df)
Comment

PREVIOUS NEXT
Code Example
Python :: import statsmodels.api as sm 
Python :: todense() 
Python :: python move directory 
Python :: pygame.key.get_pressed() 
Python :: python config file 
Python :: python install bigquery 
Python :: add rectangle matplotlib 
Python :: python - exchange rate API 
Python :: blender python save file 
Python :: read pickle file python 
Python :: how to draw shape square in python turtle 
Python :: pyqt5 qpushbutton disable 
Python :: import load_iris 
Python :: parse list from string 
Python :: python prime check 
Python :: python cartesian product 
Python :: print 2d array in python 
Python :: media django 
Python :: python pip install 
Python :: get columns that contain null values pandas 
Python :: dictionary function fromkeys in python 
Python :: puissance python 
Python :: get stock data in python 
Python :: if in lambda function python 
Python :: sklearn cross validation score 
Python :: django rest framework default_authentication_classes 
Python :: count values pandas 
Python :: print () 
Python :: how to iterate pyspark dataframe 
Python :: python center window 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =