Site icon DataFlair

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)])

 

Exit mobile version