pandas filter on range of values

Solutions on MaxInterview for pandas filter on range of values by the best coders in the world

showing results for - "pandas filter on range of values"
Sofia
05 Apr 2018
1import pandas as pd
2
3#initialize dataframe
4df = pd.DataFrame({'a': [2, 4, 8, 5], 'b': [2, 0, 9, 7]})
5
6#check if the values of df['a'] are in the range(3,6)
7out = df['a'].isin(range(3,6))
8
9#filter dataframe
10filtered_df = df[out]
11
12print('Original DataFrame\n-------------------\n',df)
13print('\nFiltered DataFrame\n-------------------\n',filtered_df)