Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas filter with given value

Method 1: Selecting rows of Pandas Dataframe based on particular column value using ‘>’, ‘=’, ‘=’, ‘<=’, ‘!=’ operator.

Example 1: Selecting all the rows from the given Dataframe in which ‘Percentage’ is greater than 75 using [ ].

Python3
# selecting rows based on condition 
rslt_df = dataframe[dataframe['Percentage'] > 70] 
    
print('
Result dataframe :
', rslt_df)
Comment

pandas filter rows by value

# does year equals to 2002?
# is_2002 is a boolean variable with True or False in it
>is_2002 =  gapminder['year']==2002
>print(is_2002.head())
0    False
1    False
2    False
3    False
4    False
# filter rows for year 2002 using  the boolean variable
>gapminder_2002 = gapminder[is_2002]
>print(gapminder_2002.shape)
(142, 6)
Comment

PREVIOUS NEXT
Code Example
Python :: remove first character of string python 
Python :: sort a list of array python 
Python :: python add two numbers 
Python :: root mean squared error 
Python :: difference between __str__ and __repr__ 
Python :: ad background image with tkinter 
Python :: radix sort in python 
Python :: installation of uvicorn with only pure python dependencies 
Python :: networkx max degree node 
Python :: how to get colored text in python 
Python :: creating a pandas df 
Python :: python if in list multiple 
Python :: save_img keras 
Python :: django filter by date range 
Python :: python web parse 
Python :: python send image server 
Python :: pandas where 
Python :: redis json python 
Python :: how to remove spaces in string in python 
Python :: remove substring from string python 
Python :: delete dataframe from memory python 
Python :: rotate image python 
Python :: python cv2 convert image to binary 
Python :: tensor vs numpy array 
Python :: python tuple vs list 
Python :: get page title by python bs4 
Python :: python import from parent directory 
Python :: binary to decimal conversion python 
Python :: management commands django 
Python :: django sessions 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =