Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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)
Source by pythonexamples.org #
 
PREVIOUS NEXT
Tagged: #pandas #filter #range #values
ADD COMMENT
Topic
Name
4+5 =