We will use contains() to get only rows having ar in name column. We used the option case=False so this is a case insensitive matching. You can make it case sensitive by changing case option to case=True
id name class mark
2 3 Arnold1 #Three 55
3 4 Krish0 Four 60
5 6 Krish Four, 60
6 7 Max %Three 85
Deleting the rows matching the condition
In all above cases we have displayed matching rows. We can use drop() to delete the matching rows and return the balance. Note that drop() will not change the main DataFrame.
Deleting the rows having 0 in name column.
id name class mark
1 2 Ma51 Three 85
3 4 Krish0 Four 60
4 5 Roni 7Four 60
Delete rows having ? in Page column
From a list of Pages ( URLs) we want to remove the pages having query string. Here Page is our column name of DdataFrame df.
df=df[~df.Page.str.contains('\?')]
Combine conditions
Here three conditions are used by using OR matching. Final output will contain all rows matching to any one or more conditions.
str1 = df["id"] == 5 # id column value
str2 = df.name.str.contains("Al", case=False) # name column value matching Al
str3 = df["mark"] < 50 # mark column value less than 50
df2 = df[str1 | str2 | str3] # combine all conditions using | operator