How to Apply Filter in Pandas

Get Job-Ready: Data Analysis using Python with 70+ Projects Start Now!!

Program 1

Pandas Dataset

# Filter in Python
import pandas as pd
myfile="D://mypandas/employee2.xlsx"
df=pd.read_excel(myfile)
#print(df.loc[(df['totalsalary']>10000)])
# and  &   or |   not ~
#print(df.loc[(df['gender']=='male') & (df['totalsalary']>10000)])
#print(df.loc[(df['empdept']=='CS') & (df['gender']=='female')])
#print(df.loc[(df['empname'].str.contains('A')) | (df['empname'].str.contains('a'))])
#print(df.loc[(df['empname'].str.startswith('Raj'))])
#print(df.loc[~(df['totalsalary']>10000)])

 

Did you like this article? If Yes, please give DataFlair 5 Stars on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *